-
-
Notifications
You must be signed in to change notification settings - Fork 698
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
Implement redirects from old % encoding to new dash encoding #1650
Comments
This is a bit tricky. I tried this, sending a redirect only if a 404 happens: diff --git a/datasette/app.py b/datasette/app.py
index 8c5480c..420664c 100644
--- a/datasette/app.py
+++ b/datasette/app.py
@@ -1211,6 +1211,10 @@ class DatasetteRouter:
return await self.handle_404(request, send)
async def handle_404(self, request, send, exception=None):
+ # If path contains % encoding, redirect to dash encoding
+ if '%' in request.scope["path"]:
+ await asgi_send_redirect(send, request.scope["path"].replace("%", "-"))
+ return
# If URL has a trailing slash, redirect to URL without it
path = request.scope.get(
"raw_path", request.scope["path"].encode("utf8") But this URL didn't work: I was expecting that to redirect to this page: But instead it took me to another 404: This is because that URL contains both a %-escaped |
This doesn't seem to work. https://latest.datasette.io/fixtures/table%2Fwith%2Fslashes.csv should be redirecting now that this is deployed - which it is, because https://latest.datasette.io/-/versions shows 644d25d - but I'm not getting that redirect. |
Same problem here: https://fivethirtyeight.datasettes.com/fivethirtyeight/ahca-2Dpolls%2Fahca_polls should redirect but doesn't. |
The problem seems to be that |
Here's the problem: datasette/datasette/utils/__init__.py Lines 1173 to 1175 in 020effe
Which is called here: datasette/datasette/views/base.py Lines 469 to 473 in 1baa030
So |
Originally posted by @simonw in #1439 (comment)
The text was updated successfully, but these errors were encountered: