Skip to content

Commit 89e0164

Browse files
committed
gh-138804: Check type in shlex.quote
1 parent f96f7c9 commit 89e0164

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

Lib/shlex.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ def join(split_command):
319319

320320
def quote(s):
321321
"""Return a shell-escaped version of the string *s*."""
322+
if not isinstance(s, str):
323+
raise TypeError(f"expected str, not {type(s)!r}")
324+
322325
if not s:
323326
return "''"
324327

Lib/test/test_shlex.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ def testQuote(self):
338338
for u in unsafe:
339339
self.assertEqual(shlex.quote("test%s'name'" % u),
340340
"'test%s'\"'\"'name'\"'\"''" % u)
341+
with self.assertRaises(TypeError):
342+
shlex.quote(42)
341343

342344
def testJoin(self):
343345
for split_command, command in [
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Check argument passed to ``shlex.quote`` to be a string

0 commit comments

Comments
 (0)