Skip to content

Commit a0a4051

Browse files
committed
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 <[email protected]>
1 parent 9d9e099 commit a0a4051

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

test/infamy/restconf.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,14 @@ class Location:
2626

2727
def xpath_to_uri(xpath, extra=None):
2828
"""Convert xpath to HTTP URI"""
29-
# If the xpath has a
3029
pattern = r'\[(.*?)=["\'](.*?)["\']\]'
3130
matches = re.findall(pattern, xpath)
3231

32+
uri_path = xpath
3333
if matches:
3434
for key, value in matches:
3535
# replace [key=value] with =value
36-
uri_path = re.sub(rf'\[{re.escape(key)}=["\']{re.escape(value)}["\']\]', f'={value}', xpath)
37-
else:
38-
uri_path = xpath
36+
uri_path = re.sub(rf'\[{re.escape(key)}=["\']{re.escape(value)}["\']\]', f'={value}', uri_path)
3937

4038
# Append extra if provided
4139
if extra is not None:

0 commit comments

Comments
 (0)