Skip to content

function append_slash_redirect misredirects #1972

@arabidopsis

Description

@arabidopsis

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions