Skip to content

Commit

Permalink
stateengine plugin: fix/improve conversion of lists in items
Browse files Browse the repository at this point in the history
  • Loading branch information
onkelandy committed Sep 25, 2024
1 parent 98c1461 commit 1d52c52
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions stateengine/StateEngineTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,16 @@ def convert_str_to_list(value, force=True):
try:
elements = re.findall(r"'([^']+)'|([^,]+)", value)
flattened_elements = [element[0] if element[0] else element[1] for element in elements]
formatted_str = "[" + ", ".join(
["'" + element.strip(" '\"") + "'" for element in flattened_elements]) + "]"
formatted_elements = []
for element in flattened_elements:
element = element.strip(" '\"")
if "'" in element:
formatted_elements.append(f'"{element}"')
elif '"' in element:
formatted_elements.append(f"'{element}'")
else:
formatted_elements.append(f"'{element}'")
formatted_str = "[" + ", ".join(formatted_elements) + "]"
return literal_eval(formatted_str)
except Exception as ex:
raise ValueError("Problem converting string to list: {}".format(ex))
Expand Down

0 comments on commit 1d52c52

Please sign in to comment.