Skip to content

Commit

Permalink
Remove leading slashes in 404 redirections
Browse files Browse the repository at this point in the history
When reaching http://server//page/ the server should not redirect to ``/page`` instead of ``//page``.
  • Loading branch information
leplatrem committed Feb 26, 2021
1 parent 78539af commit 6db74a4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pollbot/middlewares.py
Expand Up @@ -61,7 +61,7 @@ async def handle_any(request, response):
async def handle_404(request, response):
if 'json' not in response.headers['Content-Type']:
if request.path.endswith('/'):
return web.HTTPFound(request.path.rstrip('/'))
return web.HTTPFound('/' + request.path.strip('/'))
return web.json_response({
"status": 404,
"message": "Page '{}' not found".format(request.path)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_views.py
Expand Up @@ -61,6 +61,11 @@ async def test_redirects_trailing_slashes(cli):
assert resp.headers['Location'] == "/v1/firefox/54.0"


async def test_redirects_strip_leading_slashes(cli):
resp = await check_response(cli, "//page/", status=302, allow_redirects=False)
assert resp.headers['Location'] == "/page"


async def check_yaml_resource(cli, url, filename, **kwargs):
with open(os.path.join(HERE, "..", "pollbot", filename)) as stream:
content = yaml.safe_load(stream)
Expand Down

0 comments on commit 6db74a4

Please sign in to comment.