Jelajahi Sumber

Collector issue 152: respect quotes to group arguments.

Chris McDonough 19 tahun lalu
induk
melakukan
a42c223770
2 mengubah file dengan 18 tambahan dan 1 penghapusan
  1. 2 1
      src/supervisor/supervisord.py
  2. 16 0
      src/supervisor/tests.py

+ 2 - 1
src/supervisor/supervisord.py

@@ -29,6 +29,7 @@ import resource
 import stat
 import re
 import tempfile
+import shlex
 
 from fcntl import fcntl
 from fcntl import F_SETFL, F_GETFL
@@ -113,7 +114,7 @@ class Subprocess:
     def get_execv_args(self):
         """Internal: turn a program name into a file name, using $PATH,
         make sure it exists """
-        commandargs = self.config.command.split()
+        commandargs = shlex.split(self.config.command)
 
         program = commandargs[0]
 

+ 16 - 0
src/supervisor/tests.py

@@ -1079,6 +1079,14 @@ class SubprocessTests(unittest.TestCase):
         args = instance.get_execv_args()
         self.assertEqual(args, ('/notthere', ['/notthere'], None))
 
+    def test_get_execv_args_abs_withquotes_missing(self):
+        options = DummyOptions()
+        config = DummyPConfig('notthere', '/notthere "an argument"')
+        instance = self._makeOne(options, config)
+        args = instance.get_execv_args()
+        self.assertEqual(args, ('/notthere', ['/notthere', 'an argument'],
+                                None))
+
     def test_get_execv_args_rel_missing(self):
         options = DummyOptions()
         config = DummyPConfig('notthere', 'notthere')
@@ -1086,6 +1094,13 @@ class SubprocessTests(unittest.TestCase):
         args = instance.get_execv_args()
         self.assertEqual(args, (None, ['notthere'], None))
 
+    def test_get_execv_args_rel_withquotes_missing(self):
+        options = DummyOptions()
+        config = DummyPConfig('notthere', 'notthere "an argument"')
+        instance = self._makeOne(options, config)
+        args = instance.get_execv_args()
+        self.assertEqual(args, (None, ['notthere', 'an argument'], None))
+
     def test_get_execv_args_abs(self):
         executable = '/bin/sh foo'
         options = DummyOptions()
@@ -1105,6 +1120,7 @@ class SubprocessTests(unittest.TestCase):
         self.assertEqual(args[0], '/bin/sh')
         self.assertEqual(args[1], ['sh', 'foo'])
         self.assertEqual(len(args[2]), 10)
+
         
     def test_spawn_already_running(self):
         options = DummyOptions()