]> granicus.if.org Git - python/commitdiff
Fix issue 1300: Quote command line arguments that contain a '|' character in
authorGregory P. Smith <greg@mad-scientist.com>
Sat, 19 Jan 2008 22:49:37 +0000 (22:49 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Sat, 19 Jan 2008 22:49:37 +0000 (22:49 +0000)
subprocess.list2cmdline (windows).

Lib/subprocess.py
Lib/test/test_subprocess.py

index bae42599fe5d5740c45a86d36fca30421403c589..975a924aba340367d55f95b7e76ff89fae63304d 100644 (file)
@@ -471,8 +471,8 @@ def list2cmdline(seq):
 
     2) A string surrounded by double quotation marks is
        interpreted as a single argument, regardless of white space
-       contained within.  A quoted string can be embedded in an
-       argument.
+       or pipe characters contained within.  A quoted string can be
+       embedded in an argument.
 
     3) A double quotation mark preceded by a backslash is
        interpreted as a literal double quotation mark.
@@ -498,7 +498,7 @@ def list2cmdline(seq):
         if result:
             result.append(' ')
 
-        needquote = (" " in arg) or ("\t" in arg) or not arg
+        needquote = (" " in arg) or ("\t" in arg) or ("|" in arg) or not arg
         if needquote:
             result.append('"')
 
index a7e309ef5642805c733ee3c6c1f14d1b0facf17c..9886f3d8fa2cf1b2c7d2b5dd5f85e47a41b52ced 100644 (file)
@@ -434,6 +434,8 @@ class ProcessTestCase(unittest.TestCase):
                          '"a\\\\b\\ c" d e')
         self.assertEqual(subprocess.list2cmdline(['ab', '']),
                          'ab ""')
+        self.assertEqual(subprocess.list2cmdline(['echo', 'foo|bar']),
+                         'echo "foo|bar"')
 
 
     def test_poll(self):