summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bangert <ben@groovie.org>2009-01-02 15:06:48 -0800
committerBen Bangert <ben@groovie.org>2009-01-02 15:06:48 -0800
commit1f8aa360cf0d82e335dfc36366722c4cb2e99157 (patch)
treea40b73ab71d641639e3f97259a6224933cc6a31b
parentb07e3e588b5634cecb1034acb7cdda28f457ae65 (diff)
downloadroutes-1f8aa360cf0d82e335dfc36366722c4cb2e99157.tar.gz
* Bugfix for unicode encoding problems with non-minimized Route generation.
Spotted by Wichert Akkerman. --HG-- branch : trunk
-rw-r--r--CHANGELOG2
-rw-r--r--routes/route.py5
-rw-r--r--tests/test_functional/test_nonminimization.py31
3 files changed, 38 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index fa770ac..14b28d6 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,8 @@ Routes Changelog
========================
-- 1.10.2 (**tip**)
+* Bugfix for unicode encoding problems with non-minimized Route generation.
+ Spotted by Wichert Akkerman.
* Bugfix for when environ is {} in unit tests.
-- 1.10.1 (September 27, 2008)
diff --git a/routes/route.py b/routes/route.py
index c80cce2..cb8479b 100644
--- a/routes/route.py
+++ b/routes/route.py
@@ -534,6 +534,11 @@ class Route(object):
for arg in self.minkeys:
if arg not in kargs or kargs[arg] is None:
return False
+
+ # Encode all the argument that the regpath can use
+ for k in kargs:
+ if k in self.maxkeys:
+ kargs[k] = url_quote(kargs[k], self.encoding)
return self.regpath % kargs
def generate_minimized(self, kargs):
diff --git a/tests/test_functional/test_nonminimization.py b/tests/test_functional/test_nonminimization.py
index fdd3483..b18a901 100644
--- a/tests/test_functional/test_nonminimization.py
+++ b/tests/test_functional/test_nonminimization.py
@@ -1,7 +1,9 @@
"""Test non-minimization recognition"""
+import urllib
from nose.tools import eq_
+from routes import url_for
from routes.mapper import Mapper
@@ -111,3 +113,32 @@ def test_regexp_syntax():
eq_(None, m.generate(controller='content', id=4))
eq_('/content/index/43', m.generate(controller='content', id=43))
eq_('/content/view/31', m.generate(controller='content', action='view', id=31))
+
+def test_unicode():
+ hoge = u'\u30c6\u30b9\u30c8' # the word test in Japanese
+ hoge_enc = urllib.quote(hoge.encode('utf-8'))
+ m = Mapper()
+ m.minimization = False
+ m.connect(':hoge')
+ eq_("/%s" % hoge_enc, m.generate(hoge=hoge))
+ assert isinstance(m.generate(hoge=hoge), str)
+
+def test_unicode_static():
+ hoge = u'\u30c6\u30b9\u30c8' # the word test in Japanese
+ hoge_enc = urllib.quote(hoge.encode('utf-8'))
+ m = Mapper()
+ m.minimization = False
+ m.connect('google-jp', 'http://www.google.co.jp/search', _static=True)
+ m.create_regs(['messages'])
+ eq_("http://www.google.co.jp/search?q=" + hoge_enc,
+ url_for('google-jp', q=hoge))
+ assert isinstance(url_for('google-jp', q=hoge), str)
+
+def test_other_special_chars():
+ m = Mapper()
+ m.minimization = False
+ m.connect('/:year/:(slug).:(format),:(locale)', locale='en', format='html')
+ m.create_regs(['content'])
+
+ assert '/2007/test.xml,ja' == m.generate(year=2007, slug='test', format='xml', locale='ja')
+ assert None == m.generate(year=2007, format='html')