bpo-34266: [pdb] handle ValueError from shlex.split() (GH-26656)

This commit is contained in:
Irit Katriel 2021-07-03 16:33:35 +01:00 committed by GitHub
parent 556d5ad11f
commit d968a638fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View File

@ -1026,7 +1026,11 @@ class Pdb(bdb.Bdb, cmd.Cmd):
if arg:
import shlex
argv0 = sys.argv[0:1]
sys.argv = shlex.split(arg)
try:
sys.argv = shlex.split(arg)
except ValueError as e:
self.error('Cannot run %s: %s' % (arg, e))
return
sys.argv[:0] = argv0
# this is caught in the main debugger loop
raise Restart

View File

@ -1800,6 +1800,21 @@ def bœr():
'(Pdb) ',
])
def test_issue34266(self):
'''do_run handles exceptions from parsing its arg'''
def check(bad_arg, msg):
commands = "\n".join([
f'run {bad_arg}',
'q',
])
stdout, _ = self.run_pdb_script('pass', commands + '\n')
self.assertEqual(stdout.splitlines()[1:], [
'-> pass',
f'(Pdb) *** Cannot run {bad_arg}: {msg}',
'(Pdb) ',
])
check('\\', 'No escaped character')
check('"', 'No closing quotation')
def test_issue42384(self):
'''When running `python foo.py` sys.path[0] is an absolute path. `python -m pdb foo.py` should behave the same'''

View File

@ -0,0 +1 @@
Handle exceptions from parsing the arg of :mod:`pdb`'s run/restart command.