Skip to content

Commit

Permalink
Merge pull request #131 from StackStorm/issue-130/quotes_in_shorthand
Browse files Browse the repository at this point in the history
Value in quotes in shorthand publish should be evaluated as string type
  • Loading branch information
jinpingh authored Feb 15, 2019
2 parents a81f5ee + a927913 commit 2b520c6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
19 changes: 19 additions & 0 deletions orquesta/tests/unit/utils/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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), [])
Expand Down
16 changes: 13 additions & 3 deletions orquesta/utils/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit 2b520c6

Please sign in to comment.