Skip to content
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

fix: support static files with spaces in their names #2450

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions datasette/utils/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
from datasette.utils import MultiParams, calculate_etag
from mimetypes import guess_type
from urllib.parse import parse_qs, urlunparse, parse_qsl
from urllib.parse import parse_qs, urlunparse, parse_qsl, unquote
from pathlib import Path
from http.cookies import SimpleCookie, Morsel
import aiofiles
Expand Down Expand Up @@ -318,7 +318,7 @@ async def inner_static(request, send):
path = request.scope["url_route"]["kwargs"]["path"]
headers = static_headers.copy()
try:
full_path = (root_path / path).resolve().absolute()
full_path = (root_path / unquote(path)).resolve().absolute()
except FileNotFoundError:
await asgi_send_html(send, "404: Directory not found", 404)
return
Expand Down
8 changes: 8 additions & 0 deletions tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ def test_static_mounts():
) as client:
response = client.get("/custom-static/test_html.py")
assert response.status_code == 200
response = client.get(
"/custom-static/test_templates/pages/nested/filename with spaces"
)
assert response.status_code == 200
response = client.get(
"/custom-static/test_templates/pages/topic_{topic}/{slug}.html"
)
assert response.status_code == 200
response = client.get("/custom-static/not_exists.py")
assert response.status_code == 404
response = client.get("/custom-static/../LICENSE")
Expand Down
Empty file.
Loading