diff --git a/starlette/staticfiles.py b/starlette/staticfiles.py index 02848241e..637da6480 100644 --- a/starlette/staticfiles.py +++ b/starlette/staticfiles.py @@ -153,6 +153,7 @@ def lookup_path(self, path: str) -> tuple[str, os.stat_result | None]: joined_path = os.path.join(directory, path) if self.follow_symlink: full_path = os.path.abspath(joined_path) + directory = os.path.abspath(directory) else: full_path = os.path.realpath(joined_path) directory = os.path.realpath(directory) diff --git a/tests/test_staticfiles.py b/tests/test_staticfiles.py index 2c5e7e2df..e11e3cb30 100644 --- a/tests/test_staticfiles.py +++ b/tests/test_staticfiles.py @@ -593,3 +593,11 @@ def test_staticfiles_self_symlinks(tmp_path: Path, test_client_factory: TestClie assert response.url == "http://testserver/index.html" assert response.status_code == 200 assert response.text == "

Hello

" + + +def test_staticfiles_relative_directory_symlinks(test_client_factory: TestClientFactory) -> None: + app = StaticFiles(directory="tests/statics", follow_symlink=True) + client = test_client_factory(app) + response = client.get("/example.txt") + assert response.status_code == 200 + assert response.text == "123\n"