Skip to content

Commit b8ef5ce

Browse files
committed
Add testQuoteAlways to shlex tests
The first assertTrue test checks all strings now start with a single quote, ie they have actually been escaped The second test of assertFalse checks that not all the strings have been escaped when always=False (the default value), since the first, third, and fifth string do not need escaping unless requested.
1 parent 5f74da5 commit b8ef5ce

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

Lib/test/test_shlex.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,18 @@ def testQuote(self):
337337
self.assertEqual(shlex.quote("test%s'name'" % u),
338338
"'test%s'\"'\"'name'\"'\"''" % u)
339339

340+
def testQuoteAlways(self):
341+
strs = ['hello', 'to the', 'world', 'escape me', 'no-escape-needed']
342+
343+
# guarantee escaping all strings
344+
strs_always_escaped = [shlex.quote(s, always=True) for s in strs]
345+
self.assertTrue(all(s.startswith("'") for s in strs_always_escaped))
346+
347+
# just escape when necessary ('to the', 'escape me')
348+
strs_necessary_escaped = [shlex.quote(s, always=False) for s in strs]
349+
self.assertFalse(all(s.startswith("'")
350+
for s in strs_necessary_escaped))
351+
340352
def testJoin(self):
341353
for split_command, command in [
342354
(['a ', 'b'], "'a ' b"),

0 commit comments

Comments
 (0)