mirror of
https://github.com/python/cpython.git
synced 2025-01-19 15:05:15 +08:00
bpo-34266: [pdb] handle ValueError from shlex.split() (GH-26656)
This commit is contained in:
parent
556d5ad11f
commit
d968a638fc
@ -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
|
||||
|
@ -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'''
|
||||
|
@ -0,0 +1 @@
|
||||
Handle exceptions from parsing the arg of :mod:`pdb`'s run/restart command.
|
Loading…
Reference in New Issue
Block a user