Skip to content

Commit 6772556

Browse files
fix: add validation for nested and unbalanced parentheses in path
1 parent bbab9c3 commit 6772556

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/common/providers/address_resolver/path_to_path_items.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ def path_to_path_items(path: str) -> list[AttributeItem | QueryItem | IdItem]:
2828
"""Split up the path into path items.
2929
The path used as input to this function should not include protocol or data source.
3030
"""
31+
# Validate no nested or unbalanced parentheses in path
32+
depth = 0
33+
for char in path:
34+
if char == "(":
35+
depth += 1
36+
if depth > 1:
37+
raise ValueError(f"Nested parentheses are not supported in path: {path}")
38+
elif char == ")":
39+
depth -= 1
40+
if depth < 0:
41+
raise ValueError(f"Unbalanced parentheses in path: {path}")
42+
if depth != 0:
43+
raise ValueError(f"Unbalanced parentheses in path: {path}")
44+
3145
queries = re.findall(r"\(([^()]+)\)", path)
3246
if queries:
3347
# Split the path into the pieces surrounding the queries and remove trailing [( and )]

0 commit comments

Comments
 (0)