changeset 2528:1ae621d83c5b

fix arg parser bug, test for this bug
author Johannes Berg <johannes AT sipsolutions DOT net>
date Mon, 23 Jul 2007 11:37:05 +0200
parents 4f6f7e56eb40
children df375ab9fbde
files MoinMoin/_tests/test_wikiutil.py MoinMoin/wikiutil.py
diffstat 2 files changed, 24 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_wikiutil.py	Mon Jul 23 11:36:37 2007 +0200
+++ b/MoinMoin/_tests/test_wikiutil.py	Mon Jul 23 11:37:05 2007 +0200
@@ -266,6 +266,7 @@
                                                     u'e': u'a,b,c,d'}, [])),
                   (u'd = "", e = ',           ([], {u'd': u'', u'e': None},
                                                [])),
+                  (u'd=""',                   ([], {u'd': u''}, [])),
                   (u'd = "", e = ""',         ([], {u'd': u'', u'e': u''},
                                                [])),
                   # no, None as key isn't accepted
@@ -281,6 +282,14 @@
         for args, expected in tests:
             result = wikiutil.parse_quoted_separated(args)
             assert expected == result
+            for val in result[0]:
+                assert val is None or isinstance(val, unicode)
+            for val in result[1].keys():
+                assert val is None or isinstance(val, unicode)
+            for val in result[1].values():
+                assert val is None or isinstance(val, unicode)
+            for val in result[2]:
+                assert val is None or isinstance(val, unicode)
 
     def testLimited(self):
         tests = [
@@ -293,6 +302,14 @@
         for args, expected in tests:
             result = wikiutil.parse_quoted_separated(args, seplimit=1)
             assert expected == result
+            for val in result[0]:
+                assert val is None or isinstance(val, unicode)
+            for val in result[1].keys():
+                assert val is None or isinstance(val, unicode)
+            for val in result[1].values():
+                assert val is None or isinstance(val, unicode)
+            for val in result[2]:
+                assert val is None or isinstance(val, unicode)
 
     def testNoNameValue(self):
         abcd = [u'a', u'b', u'c', u'd']
@@ -313,6 +330,8 @@
         for args, expected in tests:
             result = wikiutil.parse_quoted_separated(args, name_value=False)
             assert expected == result
+            for val in result:
+                assert val is None or isinstance(val, unicode)
 
 
 class TestArgGetters:
--- a/MoinMoin/wikiutil.py	Mon Jul 23 11:36:37 2007 +0200
+++ b/MoinMoin/wikiutil.py	Mon Jul 23 11:37:05 2007 +0200
@@ -1223,12 +1223,14 @@
               a list of trailing arguments
     """
     idx = 0
+    if not isinstance(args, unicode):
+        raise TypeError('args must be unicode')
     max = len(args)
     ret_positional = [] # positional argument return value
     ret_trailing = []   # trailing arguments return value
     positional = ret_positional
     keyword = {}        # keyword arguments
-    curname = ''        # current name, initially value as well (name=value)
+    curname = u''       # current name, initially value as well (name=value)
     cur = None          # current value
     cur_quoted = False  # indicates whether value was quoted,
                         # needed None vs. u'' handling
@@ -1267,7 +1269,7 @@
                 curname = curname + spaces
         elif not quoted and name_value and char == '=':
             if cur is None:
-                cur = ''
+                cur = u''
                 cur_quoted = False
             else:
                 cur += '='
@@ -1283,7 +1285,7 @@
                 positional = ret_trailing
             else:
                 positional.append(cur)
-            curname = ''
+            curname = u''
             cur = None
             noquote = False
             cur_quoted = False