Skip to content

Commit f6a67f3

Browse files
sfrieselvereszol
authored andcommitted
Redo "Parse env configuration in posix mode"
Fixes Supervisor#328 This allows (escaped) quotes in the values as well as empty values. -- This was done in pull request Supervisor#329 but removed as it broke parsing empty quotes (Supervisor#873) due to a bug in shlex (http://bugs.python.org/issue21999). This bug is fixed so posix mode can be used. Brings back Supervisor#329 Partially reverts Supervisor#880
1 parent ff5356f commit f6a67f3

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
the ``[supervisorctl]`` section or ``[ctlplugin:x]`` sections to be in
1010
included files. Patch by François Granade.
1111

12+
- Parsing ``environment=`` has been improved to allow escaped quotes
13+
inside quotes and quoted empty values. Patch by Stefan Friesel.
14+
1215
4.2.5 (2022-12-23)
1316
------------------
1417

supervisor/datatypes.py

Lines changed: 2 additions & 2 deletions
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))
71+
lexer = shlex.shlex(str(arg), posix=True)
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].strip('\'"')
84+
D[k_eq_v[0]] = k_eq_v[2]
8585
i += 4
8686
return D
8787

supervisor/tests/test_datatypes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ 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+
167172
def test_handles_empty_inside_quotes(self):
168173
actual = datatypes.dict_of_key_value_pairs('foo=""')
169174
expected = {'foo': ''}

0 commit comments

Comments
 (0)