]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.10] bpo-34266: [pdb] handle ValueError from shlex.split() (GH-26656) (GH-27006)
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Sat, 3 Jul 2021 16:28:46 +0000 (17:28 +0100)
committerGitHub <noreply@github.com>
Sat, 3 Jul 2021 16:28:46 +0000 (17:28 +0100)
(cherry picked from commit d968a638fcbf9030c999cfacd4c9bf0656e779c4)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Lib/pdb.py
Lib/test/test_pdb.py
Misc/NEWS.d/next/Library/2021-06-10-21-53-46.bpo-34266.k3fxnm.rst [new file with mode: 0644]

index ff40f7b2476a38158cb189c4f18a15a889649a24..1b4ff54833fcb424ff730828dbf01573ab99cbee 100755 (executable)
@@ -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
index 3bece762558e4299429fa3b9ace0615690ba1107..cdd427a570e9fa390008f2168b7d70b97a2f9cae 100644 (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'''
diff --git a/Misc/NEWS.d/next/Library/2021-06-10-21-53-46.bpo-34266.k3fxnm.rst b/Misc/NEWS.d/next/Library/2021-06-10-21-53-46.bpo-34266.k3fxnm.rst
new file mode 100644 (file)
index 0000000..22ef84e
--- /dev/null
@@ -0,0 +1 @@
+Handle exceptions from parsing the arg of :mod:`pdb`'s run/restart command.