diff --git a/snap7/util/db.py b/snap7/util/db.py index 5f0f321e..6996d89b 100644 --- a/snap7/util/db.py +++ b/snap7/util/db.py @@ -152,8 +152,13 @@ def parse_specification(db_specification: str) -> Dict[str, Any]: for line in db_specification.split("\n"): if line and not line.lstrip().startswith("#"): - index, *var_name, _type = line.lstrip().split("#")[0].split() - var_name = " ".join(var_name) + index, *notUsed, _type = line.lstrip().split("#")[0].split() + + match = re.compile(r'(\s*)(\S+)(\s*)').findall(line) + + var_name = ''.join([m[0] + m[1] + m[2] for m in match[1:-1]]) + var_name = var_name.strip() + parsed_db_specification[var_name] = (index, _type) return parsed_db_specification diff --git a/tests/test_util.py b/tests/test_util.py index 9826623c..bd41bfca 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -449,16 +449,18 @@ def test_db_creation(self) -> None: def test_db_creation_vars_with_whitespace(self) -> None: test_array = bytearray(_bytearray * 1) test_spec = """ -52 test Byte BYTE -57 supportByte BYTE + 50 testZeroSpaces BYTE + 52 testOne Space BYTE + 59 testTWo Spaces BYTE """ test_db = DB(1, test_array, test_spec, row_size=len(_bytearray), size=1, layout_offset=0, db_offset=0) exp = test_db.export() - print(exp[0].keys()) - - self.assertTrue("test Byte" in exp[0].keys()) + + self.assertTrue("testZeroSpaces" in exp[0].keys()) + self.assertTrue("testOne Space" in exp[0].keys()) + self.assertTrue("testTWo Spaces" in exp[0].keys()) def test_db_export(self) -> None: