Skip to content
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

function append_slash_redirect misredirects #1972

Closed
arabidopsis opened this issue Nov 20, 2020 · 2 comments · Fixed by #2338
Closed

function append_slash_redirect misredirects #1972

arabidopsis opened this issue Nov 20, 2020 · 2 comments · Fixed by #2338
Milestone

Comments

@arabidopsis
Copy link
Contributor

file test.py

from flask import Flask, request
from werkzeug.utils import append_slash_redirect

app = Flask("test")

@app.route('/<path:path>')
def r(path):
    if not path.endswith('/'):
        return append_slash_redirect(request.environ)
    return path

run FLASK_APP=test.py flask run

A request for http://localhost:5000/parent/child gives a redirect that browsers interpret as http://localhost:5000/parent/parent/child/

Expecting a redirect that browsers interpret as http://localhost:5000/parent/child/

Possible solution:

The code strips the front '/' which leads to this situation. i.e. the returned location header is relative: 'parent/child/'
Use environ["PATH_INFO"].rstrip("/") + "/" instead

@davidism
Copy link
Member

Duplicate of #1538

@davidism davidism marked this as a duplicate of #1538 Nov 20, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 5, 2020
@davidism davidism added this to the 2.1.0 milestone Mar 16, 2022
@davidism
Copy link
Member

Addressed in #2338

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants