Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/shlex.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ def join(split_command):

def quote(s):
"""Return a shell-escaped version of the string *s*."""
if not isinstance(s, str):
raise TypeError(f"expected str, not {type(s)!r}")

if not s:
return "''"

Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_shlex.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ def testQuote(self):
for u in unsafe:
self.assertEqual(shlex.quote("test%s'name'" % u),
"'test%s'\"'\"'name'\"'\"''" % u)
with self.assertRaises(TypeError):
shlex.quote(42)

def testJoin(self):
for split_command, command in [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Check argument passed to ``shlex.quote`` to be a string
Loading