Skip to content

Commit bc3b400

Browse files
daviptBruno D. RodriguesKludex
authored
Allow relative directory path when follow_symlinks=True (#2896)
* Fix for StaticFiles(follow_symlinks=True, directory="some relative path") that stopped working with commit eee4cdc * Change test name * Delete test parameter --------- Co-authored-by: Bruno D. Rodrigues <bruno.rodrigues@bitsighttech.com> Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
1 parent 4915873 commit bc3b400

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

starlette/staticfiles.py

+1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ def lookup_path(self, path: str) -> tuple[str, os.stat_result | None]:
153153
joined_path = os.path.join(directory, path)
154154
if self.follow_symlink:
155155
full_path = os.path.abspath(joined_path)
156+
directory = os.path.abspath(directory)
156157
else:
157158
full_path = os.path.realpath(joined_path)
158159
directory = os.path.realpath(directory)

tests/test_staticfiles.py

+8
Original file line numberDiff line numberDiff line change
@@ -593,3 +593,11 @@ def test_staticfiles_self_symlinks(tmp_path: Path, test_client_factory: TestClie
593593
assert response.url == "http://testserver/index.html"
594594
assert response.status_code == 200
595595
assert response.text == "<h1>Hello</h1>"
596+
597+
598+
def test_staticfiles_relative_directory_symlinks(test_client_factory: TestClientFactory) -> None:
599+
app = StaticFiles(directory="tests/statics", follow_symlink=True)
600+
client = test_client_factory(app)
601+
response = client.get("/example.txt")
602+
assert response.status_code == 200
603+
assert response.text == "123\n"

0 commit comments

Comments
 (0)