Skip to content

Commit a06f5dc

Browse files
committed
f - [bugfix] [ModelicaSystemABC] fix _prepare_input_data() - ensure returned data is dict[str, str]
1 parent ef23825 commit a06f5dc

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

OMPython/modelica_system_abc.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,8 @@ def prepare_str(str_in: str) -> dict[str, str]:
765765
key_val_list: list[str] = str_in.split("=")
766766
if len(key_val_list) != 2:
767767
raise ModelicaSystemError(f"Invalid 'key=value' pair: {str_in}")
768+
if len(key_val_list[0]) == 0:
769+
raise ModelicaSystemError(f"Empty key: {str_in}")
768770

769771
input_data_from_str: dict[str, str] = {str(key_val_list[0]): str(key_val_list[1])}
770772

@@ -792,7 +794,12 @@ def prepare_str(str_in: str) -> dict[str, str]:
792794
raise ModelicaSystemError(f"Invalid input data type for set*() function: {type(item)}!")
793795
input_data = input_data | prepare_str(item)
794796
elif isinstance(input_arg, dict):
795-
input_data = input_data | input_arg
797+
input_arg_str: dict[str, str] = {}
798+
for key, val in input_arg:
799+
if not isinstance(key, str) or len(key) == 0:
800+
raise ModelicaSystemError(f"Invalid key for set*() functions: {repr(key)}")
801+
input_arg_str[key] = str(val)
802+
input_data = input_data | input_arg_str
796803
else:
797804
raise ModelicaSystemError(f"Invalid input data type for set*() function: {type(input_arg)}!")
798805

0 commit comments

Comments
 (0)