From e7f5117d608ebc38ae1597f6680d812698c1f205 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 10 Feb 2025 09:33:49 -0500 Subject: [PATCH 1/2] Fix regular expression for variable splitting. Previous code tried to escape every character, however python linters complained about illegal escapes. The expression also seemed a bit complex, so a character set seems clearer. --- scripts/py_matter_yamltests/matter_yamltests/parser.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/py_matter_yamltests/matter_yamltests/parser.py b/scripts/py_matter_yamltests/matter_yamltests/parser.py index 84f918085ea670..f40655149b879b 100644 --- a/scripts/py_matter_yamltests/matter_yamltests/parser.py +++ b/scripts/py_matter_yamltests/matter_yamltests/parser.py @@ -1225,8 +1225,7 @@ def _config_variable_substitution(self, value): # But some other tests were relying on the fact that the expression was put 'as if' in # the generated code and was resolved before being sent over the wire. For such # expressions (e.g 'myVar + 1') we need to compute it before sending it over the wire. - delimiter_regex = "(\ |\(|\)|\+|\-|\*|\/|\%)" - tokens = re.split(delimiter_regex, value) + tokens = re.split("[- ()|+*/%]", value) if len(tokens) == 0: return value From 4f0876695eee36c65768580c183fde86ccbbe6b8 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 10 Feb 2025 09:40:41 -0500 Subject: [PATCH 2/2] Add brackets to force separator to also exist in the split --- scripts/py_matter_yamltests/matter_yamltests/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/py_matter_yamltests/matter_yamltests/parser.py b/scripts/py_matter_yamltests/matter_yamltests/parser.py index f40655149b879b..5715234b40f686 100644 --- a/scripts/py_matter_yamltests/matter_yamltests/parser.py +++ b/scripts/py_matter_yamltests/matter_yamltests/parser.py @@ -1225,7 +1225,7 @@ def _config_variable_substitution(self, value): # But some other tests were relying on the fact that the expression was put 'as if' in # the generated code and was resolved before being sent over the wire. For such # expressions (e.g 'myVar + 1') we need to compute it before sending it over the wire. - tokens = re.split("[- ()|+*/%]", value) + tokens = re.split("([- ()|+*/%])", value) if len(tokens) == 0: return value