Skip to content

Commit d968a63

Browse files
authored
bpo-34266: [pdb] handle ValueError from shlex.split() (GH-26656)
1 parent 556d5ad commit d968a63

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

Lib/pdb.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,11 @@ def do_run(self, arg):
10261026
if arg:
10271027
import shlex
10281028
argv0 = sys.argv[0:1]
1029-
sys.argv = shlex.split(arg)
1029+
try:
1030+
sys.argv = shlex.split(arg)
1031+
except ValueError as e:
1032+
self.error('Cannot run %s: %s' % (arg, e))
1033+
return
10301034
sys.argv[:0] = argv0
10311035
# this is caught in the main debugger loop
10321036
raise Restart

Lib/test/test_pdb.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,21 @@ def test_errors_in_command(self):
18001800
'(Pdb) ',
18011801
])
18021802

1803+
def test_issue34266(self):
1804+
'''do_run handles exceptions from parsing its arg'''
1805+
def check(bad_arg, msg):
1806+
commands = "\n".join([
1807+
f'run {bad_arg}',
1808+
'q',
1809+
])
1810+
stdout, _ = self.run_pdb_script('pass', commands + '\n')
1811+
self.assertEqual(stdout.splitlines()[1:], [
1812+
'-> pass',
1813+
f'(Pdb) *** Cannot run {bad_arg}: {msg}',
1814+
'(Pdb) ',
1815+
])
1816+
check('\\', 'No escaped character')
1817+
check('"', 'No closing quotation')
18031818

18041819
def test_issue42384(self):
18051820
'''When running `python foo.py` sys.path[0] is an absolute path. `python -m pdb foo.py` should behave the same'''
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Handle exceptions from parsing the arg of :mod:`pdb`'s run/restart command.

0 commit comments

Comments
 (0)