kopia lustrzana https://github.com/simonw/datasette
rodzic
32548b88fd
commit
eeb58a09ee
|
@ -1211,6 +1211,13 @@ class DatasetteRouter:
|
||||||
return await self.handle_404(request, send)
|
return await self.handle_404(request, send)
|
||||||
|
|
||||||
async def handle_404(self, request, send, exception=None):
|
async def handle_404(self, request, send, exception=None):
|
||||||
|
# If path contains % encoding, redirect to dash encoding
|
||||||
|
if "%" in request.path:
|
||||||
|
# Try the same path but with "%" replaced by "-"
|
||||||
|
# and "-" replaced with "-2D"
|
||||||
|
new_path = request.path.replace("-", "-2D").replace("%", "-")
|
||||||
|
await asgi_send_redirect(send, new_path)
|
||||||
|
return
|
||||||
# If URL has a trailing slash, redirect to URL without it
|
# If URL has a trailing slash, redirect to URL without it
|
||||||
path = request.scope.get(
|
path = request.scope.get(
|
||||||
"raw_path", request.scope["path"].encode("utf8")
|
"raw_path", request.scope["path"].encode("utf8")
|
||||||
|
|
|
@ -952,3 +952,9 @@ def test_no_alternate_url_json(app_client, path):
|
||||||
assert (
|
assert (
|
||||||
'<link rel="alternate" type="application/json+datasette"' not in response.text
|
'<link rel="alternate" type="application/json+datasette"' not in response.text
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_redirect_percent_encoding_to_dash_encoding(app_client):
|
||||||
|
response = app_client.get("/fivethirtyeight/twitter-ratio%2Fsenators")
|
||||||
|
assert response.status == 302
|
||||||
|
assert response.headers["location"] == "/fivethirtyeight/twitter-2Dratio-2Fsenators"
|
||||||
|
|
Ładowanie…
Reference in New Issue