From: Petri Lehtinen Date: Sat, 23 Feb 2013 21:09:51 +0000 (+0100) Subject: Issue #16121: Fix line number accounting in shlex X-Git-Tag: v3.3.1rc1~132 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6d61eaa0d0d89b0e035ce75d810280515befc17a;p=thirdparty%2FPython%2Fcpython.git Issue #16121: Fix line number accounting in shlex --- 6d61eaa0d0d89b0e035ce75d810280515befc17a diff --cc Lib/test/test_shlex.py index d4463f300481,1cd8220be0b7..5f7b68f7830b --- a/Lib/test/test_shlex.py +++ b/Lib/test/test_shlex.py @@@ -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):