8000 Return 404 Not Found for accessing file as directory pattern by xKerman · Pull Request #1124 · encode/starlette · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Return 404 Not Found for accessin 8000 g file as directory pattern #1124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion starlette/staticfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ async def lookup_path(
try:
stat_result = await aio_stat(full_path)
return (full_path, stat_result)
except FileNotFoundError:
except (FileNotFoundError, NotADirectoryError):
pass
return ("", None)

Expand Down
12 changes: 12 additions & 0 deletions tests/test_staticfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,15 @@ def test_staticfiles_html(tmpdir):
response = client.get("/missing")
assert response.status_code == 404
assert response.text == "<h1>Custom not found page</h1>"


def test_staticfiles_access_file_as_directory(tmpdir):
path = os.path.join(tmpdir, "example.txt")
with open(path, "w") as file:
file.write("<file content>")

app = StaticFiles(directory=tmpdir)
client = TestClient(app)
response = client.get("/example.txt/foo")
assert response.status_code == 404
assert response.text == "Not Found"
0