Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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 string object, got {type(s).__name__!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)
self.assertRaises(TypeError, shlex.quote, 42)
self.assertRaises(TypeError, shlex.quote, b"abc")

def testJoin(self):
for split_command, command in [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Raise :exc:`TypeError` instead of :exc:`AttributeError` when an argument of
incorrect type is passed to :func:`shlex.quote`. This restores the behavior of
that function pre-3.14.
Loading