tianwen2976 / webapp-improved

Automatically exported from code.google.com/p/webapp-improved
Other
0 stars 0 forks source link

Route.build fails when query arguments contains unicode values #50

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The URL path is encoded to unicode but not the query arguments.

What steps will reproduce the problem?

Python 2.5.5 (r255:77872, Mar 27 2011, 12:30:39)

In [1]: import webapp2

In [2]: print webapp2.__version__
2.5.1

In [3]: my_route = webapp2.Route('/')

In [4]: my_route.build(None, [], {'unicode_value':u'olá'})
---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)

/xxxxx/webapp2-2.5.1/<ipython console> in <module>()

/xxxxx/webapp2-2.5.1/webapp2.py in build(self, request, args, kwargs)
   1002
   1003         path, query = self._build(args, kwargs)
-> 1004         return _urlunsplit(scheme, netloc, path, query, anchor)
   1005
   1006     def _build(self, args, kwargs):

/xxxxx/webapp2-2.5.1/webapp2.py in _urlunsplit(scheme, netloc, path, query, 
fragment)
   1888
   1889         # Sort args: commonly needed to build signatures for services.
-> 1890         query = urllib.urlencode(sorted(query))
   1891
   1892     if fragment:

/usr/local/lib/python2.5/urllib.pyc in urlencode(query, doseq)
   1248         for k, v in query:
   1249             k = quote_plus(str(k))
-> 1250             v = quote_plus(str(v))
   1251             l.append(k + '=' + v)
   1252     else:

UnicodeEncodeError: 'ascii' codec can't encode characters in position 2-3: 
ordinal not in range(128)

Original issue reported on code.google.com by schettino72@gmail.com on 5 Mar 2012 at 4:53

GoogleCodeExporter commented 9 years ago
patch to fix the issue with tests...

Original comment by schettino72@gmail.com on 5 Mar 2012 at 4:56

Attachments: