Skip to content

Commit 9ae5463

Browse files
committed
[bugfix] [ModelicaSystemABC] fix _prepare_input_data() - ensure returned data is dict[str, str]
1 parent 2c0ee3b commit 9ae5463

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

OMPython/modelica_system_abc.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,10 @@ 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

769-
input_data_from_str: dict[str, str] = {key_val_list[0]: key_val_list[1]}
771+
input_data_from_str: dict[str, str] = {str(key_val_list[0]): str(key_val_list[1])}
770772

771773
return input_data_from_str
772774

@@ -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.items():
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)