mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-01 13:23:01 +02:00
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 <troglobit@gmail.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user