{"html_url": "https://github.com/simonw/datasette/issues/1650#issuecomment-1060836262", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1650", "id": 1060836262, "node_id": "IC_kwDOBm6k_c4_OxOm", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-03-07T15:52:09Z", "updated_at": "2022-03-07T15:52:09Z", "author_association": "OWNER", "body": "This is a bit tricky.\r\n\r\nI tried this, sending a redirect only if a 404 happens:\r\n\r\n```diff\r\ndiff --git a/datasette/app.py b/datasette/app.py\r\nindex 8c5480c..420664c 100644\r\n--- a/datasette/app.py\r\n+++ b/datasette/app.py\r\n@@ -1211,6 +1211,10 @@ class DatasetteRouter:\r\n return await self.handle_404(request, send)\r\n \r\n async def handle_404(self, request, send, exception=None):\r\n+ # If path contains % encoding, redirect to dash encoding\r\n+ if '%' in request.scope[\"path\"]:\r\n+ await asgi_send_redirect(send, request.scope[\"path\"].replace(\"%\", \"-\"))\r\n+ return\r\n # If URL has a trailing slash, redirect to URL without it\r\n path = request.scope.get(\r\n \"raw_path\", request.scope[\"path\"].encode(\"utf8\")\r\n```\r\nBut this URL didn't work:\r\n\r\n- http://127.0.0.1:8001/fivethirtyeight/twitter-ratio%2Fsenators\r\n\r\nI was expecting that to redirect to this page:\r\n\r\n- http://127.0.0.1:8001/fivethirtyeight/twitter-2Dratio-2Fsenators\r\n\r\nBut instead it took me to another 404:\r\n\r\n- http://127.0.0.1:8001/fivethirtyeight/twitter-ratio%2Fsenators\r\n\r\nThis is because that URL contains both a %-escaped `/` AND a plain `-` - which was not escaped in the old system but is escaped in the new system.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1160750713, "label": "Implement redirects from old % encoding to new dash encoding"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1650#issuecomment-1060863311", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1650", "id": 1060863311, "node_id": "IC_kwDOBm6k_c4_O31P", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-03-07T16:13:17Z", "updated_at": "2022-03-07T16:13:17Z", "author_association": "OWNER", "body": "This doesn't seem to work.\r\n\r\nhttps://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 644d25d1de78a36b105cca479e7b3e4375a6eadc - but I'm not getting that redirect.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1160750713, "label": "Implement redirects from old % encoding to new dash encoding"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1650#issuecomment-1060864823", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1650", "id": 1060864823, "node_id": "IC_kwDOBm6k_c4_O4M3", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-03-07T16:14:33Z", "updated_at": "2022-03-07T16:14:33Z", "author_association": "OWNER", "body": "Same problem here: https://fivethirtyeight.datasettes.com/fivethirtyeight/ahca-2Dpolls%2Fahca_polls should redirect but doesn't.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1160750713, "label": "Implement redirects from old % encoding to new dash encoding"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1650#issuecomment-1061038414", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1650", "id": 1061038414, "node_id": "IC_kwDOBm6k_c4_PilO", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-03-07T19:14:04Z", "updated_at": "2022-03-07T19:14:04Z", "author_association": "OWNER", "body": "The problem seems to be that `http://127.0.0.1:8002/fixtures/table%2Fwith%2Fslashes.csv` doesn't result in a 404 at all. If it did, it would be redirected.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1160750713, "label": "Implement redirects from old % encoding to new dash encoding"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1650#issuecomment-1061041034", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1650", "id": 1061041034, "node_id": "IC_kwDOBm6k_c4_PjOK", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-03-07T19:16:51Z", "updated_at": "2022-03-07T19:16:51Z", "author_association": "OWNER", "body": "Here's the problem: https://github.com/simonw/datasette/blob/020effe47bf89f35182960a9645f2383a42ebd54/datasette/utils/__init__.py#L1173-L1175\r\n\r\nWhich is called here:\r\n\r\nhttps://github.com/simonw/datasette/blob/1baa030eca375f839f3471237547ab403523e643/datasette/views/base.py#L469-L473\r\n\r\nSo `table%2Fwith%2Fslashes` ends up decoded as if it was using dash encoding.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1160750713, "label": "Implement redirects from old % encoding to new dash encoding"}, "performed_via_github_app": null}