pull/2450/merge
Andrew Grechkin 2025-10-01 22:55:18 +05:30 zatwierdzone przez GitHub
commit 51fd8eafd3
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
3 zmienionych plików z 10 dodań i 2 usunięć

Wyświetl plik

@ -2,7 +2,7 @@ import hashlib
import json import json
from datasette.utils import MultiParams, calculate_etag from datasette.utils import MultiParams, calculate_etag
from mimetypes import guess_type 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 pathlib import Path
from http.cookies import SimpleCookie, Morsel from http.cookies import SimpleCookie, Morsel
import aiofiles import aiofiles
@ -318,7 +318,7 @@ def asgi_static(root_path, chunk_size=4096, headers=None, content_type=None):
path = request.scope["url_route"]["kwargs"]["path"] path = request.scope["url_route"]["kwargs"]["path"]
headers = static_headers.copy() headers = static_headers.copy()
try: try:
full_path = (root_path / path).resolve().absolute() full_path = (root_path / unquote(path)).resolve().absolute()
except FileNotFoundError: except FileNotFoundError:
await asgi_send_html(send, "404: Directory not found", 404) await asgi_send_html(send, "404: Directory not found", 404)
return return

Wyświetl plik

@ -115,6 +115,14 @@ def test_static_mounts():
) as client: ) as client:
response = client.get("/custom-static/test_html.py") response = client.get("/custom-static/test_html.py")
assert response.status_code == 200 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") response = client.get("/custom-static/not_exists.py")
assert response.status_code == 404 assert response.status_code == 404
response = client.get("/custom-static/../LICENSE") response = client.get("/custom-static/../LICENSE")