Commits

Jun Omae committed 816014f

0.12.3dev: `parse_arg_list` should return unicode keys.

A part of #10121 (commentticket10121:11).

Comments (0)

Files changed (2)

         else:
             (name, value) = (nv[0], empty)
         name = unquote(name.replace('+', ' '))
-        if isinstance(name, unicode):
-            name = name.encode('utf-8')
+        if isinstance(name, str):
+            name = unicode(name, 'utf-8')
         value = unquote(value.replace('+', ' '))
-        if not isinstance(value, unicode):
+        if isinstance(value, str):
             value = unicode(value, 'utf-8')
         args.append((name, value))
     return args

trac/web/tests/api.py

 # -*- coding: utf-8 -*-
 
 from trac.test import Mock
-from trac.web.api import Request, RequestDone
+from trac.web.api import Request, RequestDone, parse_arg_list
 
 from StringIO import StringIO
 import unittest
         self.assertEqual('bar', req.args['action'])
 
 
+class ParseArgListTestCase(unittest.TestCase):
+
+    def test_qs_str(self):
+        args = parse_arg_list('k%C3%A9y=resum%C3%A9&r%C3%A9sum%C3%A9')
+        self.assertTrue(unicode, type(args[0][0]))
+        self.assertTrue(unicode, type(args[0][1]))
+        self.assertEqual(u'kéy', args[0][0])
+        self.assertEqual(u'resumé', args[0][1])
+        self.assertTrue(unicode, type(args[1][0]))
+        self.assertEqual(u'résumé', args[1][0])
+
+    def test_qs_unicode(self):
+        args = parse_arg_list(u'ké%3Dy=re%26su=mé&résu%26mé')
+        self.assertTrue(unicode, type(args[0][0]))
+        self.assertTrue(unicode, type(args[0][1]))
+        self.assertEqual(u'ké=y', args[0][0])
+        self.assertEqual(u're&su=mé', args[0][1])
+        self.assertTrue(unicode, type(args[1][0]))
+        self.assertEqual(u'résu&mé', args[1][0])
+
+
 def suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(RequestTestCase, 'test'))
+    suite.addTest(unittest.makeSuite(ParseArgListTestCase, 'test'))
     return suite
 
 if __name__ == '__main__':