diff --git a/orquesta/tests/unit/utils/test_parameters.py b/orquesta/tests/unit/utils/test_parameters.py index 6d8a3cfd..b644a7cc 100644 --- a/orquesta/tests/unit/utils/test_parameters.py +++ b/orquesta/tests/unit/utils/test_parameters.py @@ -96,6 +96,25 @@ def test_parse_bool_input(self): for s, d in tests: self.assertListEqual(params.parse_inline_params(s), d) + def test_parse_string_in_quotes_input(self): + tests = [ + ('x="true"', [{'x': "true"}]), + ('y="True"', [{'y': "True"}]), + ('c="TRUE"', [{'c': "TRUE"}]), + ('d="123"', [{'d': '123'}]), + ('e="abcde"', [{'e': 'abcde'}]), + ('f=""', [{'f': ''}]), + ("x='false'", [{'x': 'false'}]), + ("y='False'", [{'y': 'False'}]), + ("c='FALSE'", [{'c': 'FALSE'}]), + ("d='123'", [{'d': '123'}]), + ("e='abcde'", [{'e': 'abcde'}]), + ("f=''", [{'f': ''}]) + ] + + for s, d in tests: + self.assertListEqual(params.parse_inline_params(s), d) + def test_parse_other_types(self): self.assertListEqual(params.parse_inline_params(123), []) self.assertListEqual(params.parse_inline_params(True), []) diff --git a/orquesta/utils/parameters.py b/orquesta/utils/parameters.py index 22a9c54a..de7b145f 100644 --- a/orquesta/utils/parameters.py +++ b/orquesta/utils/parameters.py @@ -53,6 +53,9 @@ def parse_inline_params(s, preserve_order=True): # Remove leading and trailing whitespaces. v = v.strip() + quotes_in_param = bool(re.findall(REGEX_VALUE_IN_QUOTES, v) or + re.findall(REGEX_VALUE_IN_APOSTROPHES, v)) + # Remove leading and trailing double quotes. v = re.sub('^"', '', v) v = re.sub('"$', '', v) @@ -61,12 +64,19 @@ def parse_inline_params(s, preserve_order=True): v = re.sub("^'", '', v) v = re.sub("'$", '', v) - if v.lower() == 'true' or v.lower() == 'false': - v = v.lower() + quotes_in_string = False + if v != "": + # Check if param is a JSON string becuse it can be handled by json.loads() + curly_brace_in_param = v[0] == '{' and v[-1] == '}' + quotes_in_string = quotes_in_param and not curly_brace_in_param + is_bool_value = v.lower() == 'true' or v.lower() == 'false' # Load string into dictionary. try: - v = json.loads(v) + if not quotes_in_string: + if is_bool_value: + v = v.lower() + v = json.loads(v) except Exception: pass