Skip to content

Commit fa7e3f5

Browse files
committed
Fix parsing environment= with empty quoted strings
Pull #329 changed shlex to posix mode to fix quotes inside quotes (#328). A side effect of this change is that it broke parsing empty quotes (#873). This seems to be due to a bug in shlex (http://bugs.python.org/issue21999). Since no release version of Supervisor has shipped with shlex in posix mode to support quotes inside quotes, we're reverting it to fix support for empty quotes which has shipped for many Supervisor versions. Two unit tests introduced in #329 pass without posix mode, so those tests have been retained. A unit test was also added for #873 in the previous commit. Reopens #328 Partially reverts #329 Fixes #873 Closes #880
1 parent 8be5bc1 commit fa7e3f5

File tree

3 files changed

+2
-10
lines changed

3 files changed

+2
-10
lines changed

CHANGES.txt

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
- The ``supervisor`` package is no longer a namespace package.
1111

12-
- Parsing ``environment=`` has been improved to allow escaped quotes
13-
inside quotes and quoted empty values. Patch by Stefan Friesel.
14-
1512
- Added new ``stdout_syslog`` and ``stderr_syslog`` options to the config
1613
file. These are boolean options that indicate whether process output will
1714
be sent to syslog. Supervisor can now log to both files and syslog at the

supervisor/datatypes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def dict_of_key_value_pairs(arg):
6868
""" parse KEY=val,KEY2=val2 into {'KEY':'val', 'KEY2':'val2'}
6969
Quotes can be used to allow commas in the value
7070
"""
71-
lexer = shlex.shlex(str(arg), posix=True)
71+
lexer = shlex.shlex(str(arg))
7272
lexer.wordchars += '/.+-():'
7373

7474
tokens = list(lexer)
@@ -81,7 +81,7 @@ def dict_of_key_value_pairs(arg):
8181
if len(k_eq_v) != 3 or k_eq_v[1] != '=':
8282
raise ValueError(
8383
"Unexpected end of key/value pairs in value '%s'" % arg)
84-
D[k_eq_v[0]] = k_eq_v[2]
84+
D[k_eq_v[0]] = k_eq_v[2].strip('\'"')
8585
i += 4
8686
return D
8787

supervisor/tests/test_datatypes.py

-5
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,6 @@ def test_handles_newlines_inside_quotes(self):
164164
expected = {'foo': 'a\nb\nc'}
165165
self.assertEqual(actual, expected)
166166

167-
def test_handles_quotes_inside_quotes(self):
168-
actual = datatypes.dict_of_key_value_pairs('foo="\'\\""')
169-
expected = {'foo': '\'"'}
170-
self.assertEqual(actual, expected)
171-
172167
def test_handles_empty_inside_quotes(self):
173168
actual = datatypes.dict_of_key_value_pairs('foo=""')
174169
expected = {'foo': ''}

0 commit comments

Comments
 (0)