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

Moved unquoting of slashes in url to after routing #478

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions werkzeug/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ def __init__(self, map):
self.map = map

def to_python(self, value):
value = value.replace('%2F', '/')

This comment was marked as off-topic.

This comment was marked as off-topic.

return value

def to_url(self, value):
Expand Down
2 changes: 1 addition & 1 deletion werkzeug/serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def shutdown_server():
self.server.shutdown_signal = True

url_scheme = self.server.ssl_context is None and 'http' or 'https'
path_info = url_unquote(request_url.path)
path_info = url_unquote(request_url.path, unsafe='/')

environ = {
'wsgi.version': (1, 0),
Expand Down
2 changes: 1 addition & 1 deletion werkzeug/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def get_environ(self):
result.update(self.environ_base)

def _path_encode(x):
return wsgi_encoding_dance(url_unquote(x, self.charset), self.charset)
return wsgi_encoding_dance(url_unquote(x, self.charset, unsafe='/'), self.charset)

qs = wsgi_encoding_dance(self.query_string)

Expand Down
17 changes: 17 additions & 0 deletions werkzeug/testsuite/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,23 @@ def test_non_string_parts(self):
a = m.bind('example.com')
self.assert_equal(a.build('foo', {'foo': 42}), '/42')

def test_not_unquote_slashes(self):
m = r.Map([
r.Rule('/<foo>', endpoint='foo'),
r.Rule('/file:<bar>', endpoint='bar'),
r.Rule('/<path:foo>/<bar>', endpoint='foobar'),
r.Rule('/mixed/<path:mixed>', endpoint='mixed')
])
a = m.bind('example.com')
# %2F is a quoted /
self.assert_equal(a.match('/a%2Fb%2Fc'), ('foo', {'foo': 'a/b/c'}))
self.assert_equal(a.match('/%2Fb%2Fc'), ('foo', {'foo': '/b/c'}))
self.assert_equal(a.match('/%2Fb%2F'), ('foo', {'foo': '/b/'}))
self.assert_equal(a.match('/file:a%2Fb'), ('bar', {'bar': 'a/b'}))
self.assert_equal(a.match('/a/b/%2Fb%2F'), ('foobar', {'foo': 'a/b', 'bar': '/b/'}))
self.assert_equal(a.match('/mixed/a%2Fb/c'), ('mixed', {'mixed': 'a/b/c'}))
self.assert_equal(a.match('/mixed/%2F/%2Fa'), ('mixed', {'mixed': '///a'}))

def test_complex_routing_rules(self):
m = r.Map([
r.Rule('/', endpoint='index'),
Expand Down