Skip to content

Commit

Permalink
Fixed some issues with non-ascii characters in URL rules. This fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Nov 2, 2011
1 parent 68e1ba0 commit 67c8b87
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -11,6 +11,8 @@ Version 0.8.2
- The routing request redirect exception's code attribute is now
used properly.
- Fixed a bug with shutdowns on Windows.
- Fixed a few unicode issues with non-ascii characters being
hardcoded in URL rules.

Version 0.8.1
-------------
Expand Down
4 changes: 3 additions & 1 deletion werkzeug/routing.py
Expand Up @@ -715,7 +715,7 @@ def build(self, values, append_unknown=True):
return
processed.add(data)
else:
add(data)
add(url_quote(data, self.map.charset, safe='/:|'))
domain_part, url = (u''.join(tmp)).split('|', 1)

if append_unknown:
Expand Down Expand Up @@ -1121,6 +1121,8 @@ def bind(self, server_name, script_name=None, subdomain=None,
subdomain = self.default_subdomain
if script_name is None:
script_name = '/'
if isinstance(server_name, unicode):
server_name = server_name.encode('idna')
return MapAdapter(self, server_name, script_name, subdomain,
url_scheme, path_info, default_method, query_args)

Expand Down
17 changes: 17 additions & 0 deletions werkzeug/testsuite/routing.py
Expand Up @@ -609,6 +609,23 @@ def test_redirect_request_exception_code(self):
env = create_environ()
self.assert_equal(exc.get_response(env).status_code, exc.code)

def test_unicode_rules(self):
m = r.Map([
r.Rule(u'/войти/', endpoint='enter')
])
a = m.bind(u'☃.example.com')
try:
a.match(u'/войти')
except r.RequestRedirect, e:
self.assert_equal(e.new_url, 'http://xn--n3h.example.com/'
'%D0%B2%D0%BE%D0%B9%D1%82%D0%B8/')
endpoint, values = a.match(u'/войти/')
self.assert_equal(endpoint, 'enter')
self.assert_equal(values, {})

url = a.build('enter', {}, force_external=True)
self.assert_equal(url, 'http://xn--n3h.example.com/%D0%B2%D0%BE%D0%B9%D1%82%D0%B8/')


def suite():
suite = unittest.TestSuite()
Expand Down

0 comments on commit 67c8b87

Please sign in to comment.