Skip to content

werkzeug double-encodes redirects when processing merge_slashes #2157

Closed
@tomprince

Description

@tomprince
from werkzeug.routing import Rule, Map

routes = Map([
    Rule("/merge/<some>/path"),
])

def get_redirect_location(path):
    try:
        routes.bind("test.host").match(path)
    except Exception as e:
        return e.get_response({}).headers['location']
    else:
        raise ValueError("no redirect")

def test_merge_slashes():
    assert get_redirect_location("/merge/%//path") == 'http://test.host/merge/%25/path'

It looks like Rule.match uses Rule.build to generate the new path here, which is already urlencoded. But then MapAdapter.match encodes the resulting path again here.

Environment:

  • Python version: 3.9.5
  • Werkzeug version: 2.0.1

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