From a0a4051c8a51e37c7e7f7ce4f03354ccf88c2a74 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Thu, 25 Sep 2025 09:43:31 +0200 Subject: [PATCH] test/infamy: fix xpath_to_uri() to handle multiple predicates The xpath_to_uri() method only processed the first predicate in XPath expressions with multiple [key='value'] patterns. Each re.sub() call was performed on the original xpath instead of the result the previous substitutions, causing subsequent predicates to be ignored. Example XPath that would fail: /infix-firewall:firewall/zone[name='untrusted']/interface[.='e2'] Would incorrectly convert to: /infix-firewall:firewall/zone[name='untrusted']/interface=e2 Instead of the correct RESTCONF URL: /infix-firewall:firewall/zone=untrusted/interface=e2 Signed-off-by: Joachim Wiberg --- test/infamy/restconf.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/infamy/restconf.py b/test/infamy/restconf.py index 31078836..04c92201 100644 --- a/test/infamy/restconf.py +++ b/test/infamy/restconf.py @@ -26,16 +26,14 @@ class Location: def xpath_to_uri(xpath, extra=None): """Convert xpath to HTTP URI""" - # If the xpath has a pattern = r'\[(.*?)=["\'](.*?)["\']\]' matches = re.findall(pattern, xpath) + uri_path = xpath if matches: for key, value in matches: # replace [key=value] with =value - uri_path = re.sub(rf'\[{re.escape(key)}=["\']{re.escape(value)}["\']\]', f'={value}', xpath) - else: - uri_path = xpath + uri_path = re.sub(rf'\[{re.escape(key)}=["\']{re.escape(value)}["\']\]', f'={value}', uri_path) # Append extra if provided if extra is not None: