Issue #16121: Fix line number accounting in shlex
authorPetri Lehtinen <petri@digip.org>
Sat, 23 Feb 2013 21:09:51 +0000 (22:09 +0100)
committerPetri Lehtinen <petri@digip.org>
Sat, 23 Feb 2013 21:09:51 +0000 (22:09 +0100)
1  2 
Lib/shlex.py
Lib/test/test_shlex.py
Misc/ACKS
Misc/NEWS

diff --cc Lib/shlex.py
Simple merge
index d4463f300481c40766e1921799dd8cb9731367af,1cd8220be0b758b5f8645308922539541cdaa7dc..5f7b68f7830b0ff96eab280b1fc87803ceea9eea
@@@ -174,21 -173,14 +174,29 @@@ class ShlexTest(unittest.TestCase)
                               "%s: %s != %s" %
                               (self.data[i][0], l, self.data[i][1:]))
  
 +    def testQuote(self):
 +        safeunquoted = string.ascii_letters + string.digits + '@%_-+=:,./'
 +        unicode_sample = '\xe9\xe0\xdf'  # e + acute accent, a + grave, sharp s
 +        unsafe = '"`$\\!' + unicode_sample
 +
 +        self.assertEqual(shlex.quote(''), "''")
 +        self.assertEqual(shlex.quote(safeunquoted), safeunquoted)
 +        self.assertEqual(shlex.quote('test file name'), "'test file name'")
 +        for u in unsafe:
 +            self.assertEqual(shlex.quote('test%sname' % u),
 +                             "'test%sname'" % u)
 +        for u in unsafe:
 +            self.assertEqual(shlex.quote("test%s'name'" % u),
 +                             "'test%s'\"'\"'name'\"'\"''" % u)
 +
+     def testLineNumbers(self):
+         data = '"a \n b \n c"\n"x"\n"y"'
+         for is_posix in (True, False):
+             s = shlex.shlex(data, posix=is_posix)
+             for i in (1, 4, 5):
+                 s.read_token()
+                 self.assertEqual(s.lineno, i)
  
  # Allow this test to be used with old shlex.py
  if not getattr(shlex, "split", None):
diff --cc Misc/ACKS
Simple merge
diff --cc Misc/NEWS
Simple merge