From fa7e3f56c8e4fd1e6e19070a0bcffc0bf5ab3192 Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Tue, 17 Jan 2017 12:58:49 -0800 Subject: [PATCH] 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 --- CHANGES.txt | 3 --- supervisor/datatypes.py | 4 ++-- supervisor/tests/test_datatypes.py | 5 ----- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index a9e420d4d..52bdf9e4b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -9,9 +9,6 @@ - The ``supervisor`` package is no longer a namespace package. -- Parsing ``environment=`` has been improved to allow escaped quotes - inside quotes and quoted empty values. Patch by Stefan Friesel. - - Added new ``stdout_syslog`` and ``stderr_syslog`` options to the config file. These are boolean options that indicate whether process output will be sent to syslog. Supervisor can now log to both files and syslog at the diff --git a/supervisor/datatypes.py b/supervisor/datatypes.py index caae74280..d19fc2593 100644 --- a/supervisor/datatypes.py +++ b/supervisor/datatypes.py @@ -68,7 +68,7 @@ def dict_of_key_value_pairs(arg): """ parse KEY=val,KEY2=val2 into {'KEY':'val', 'KEY2':'val2'} Quotes can be used to allow commas in the value """ - lexer = shlex.shlex(str(arg), posix=True) + lexer = shlex.shlex(str(arg)) lexer.wordchars += '/.+-():' tokens = list(lexer) @@ -81,7 +81,7 @@ def dict_of_key_value_pairs(arg): if len(k_eq_v) != 3 or k_eq_v[1] != '=': raise ValueError( "Unexpected end of key/value pairs in value '%s'" % arg) - D[k_eq_v[0]] = k_eq_v[2] + D[k_eq_v[0]] = k_eq_v[2].strip('\'"') i += 4 return D diff --git a/supervisor/tests/test_datatypes.py b/supervisor/tests/test_datatypes.py index 852b19243..72902c0a5 100644 --- a/supervisor/tests/test_datatypes.py +++ b/supervisor/tests/test_datatypes.py @@ -164,11 +164,6 @@ def test_handles_newlines_inside_quotes(self): expected = {'foo': 'a\nb\nc'} self.assertEqual(actual, expected) - def test_handles_quotes_inside_quotes(self): - actual = datatypes.dict_of_key_value_pairs('foo="\'\\""') - expected = {'foo': '\'"'} - self.assertEqual(actual, expected) - def test_handles_empty_inside_quotes(self): actual = datatypes.dict_of_key_value_pairs('foo=""') expected = {'foo': ''}