Skip to content

Commit

Permalink
fixed to handle '#' and '&' as reserved char
Browse files Browse the repository at this point in the history
  • Loading branch information
okapies committed Aug 14, 2023
1 parent 2a18365 commit 6f52e15
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
22 changes: 11 additions & 11 deletions asyncua/ua/relative_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
_NS_IDX_PATTERN = re.compile(r"([0-9]*):")
_REFERENCE_TYPE_PREFIX_CHARS = "/.<"
_REFERENCE_TYPE_SUFFIX_CHAR = ">"
_INVALID_NAME_CHARS = "!:<>/."
_RESERVED_CHARS = "/.<>:#!&"


Expand Down Expand Up @@ -94,7 +93,7 @@ def _parse_name(string: str, is_reference: bool) -> Tuple[Optional[QualifiedName
name = []
head: str = ""
while len(rest) > 0:
head = _peek(rest)
head = rest[0]

if is_reference:
if head == _REFERENCE_TYPE_SUFFIX_CHAR:
Expand All @@ -103,22 +102,23 @@ def _parse_name(string: str, is_reference: bool) -> Tuple[Optional[QualifiedName
elif head in _REFERENCE_TYPE_PREFIX_CHARS:
break

if head in _INVALID_NAME_CHARS:
raise ValueError(f"Unexpected character '{head}' in browse path.")

if head == "&":
if len(rest) > 1:
name.append(rest[1])
rest = rest[2:]
continue
rest = rest[1:]
if len(rest) > 0:
head = rest[0]
if head in _RESERVED_CHARS:
name.append(head)
rest = rest[1:]
continue
raise ValueError(f"Invalid escape sequence '&{head}' in browse path.")
else:
raise ValueError("Missing escaped character following '&' in browse path.")
raise ValueError("Unexpected end after escape character '&'.")
else:
name.append(head)
rest = rest[1:]

if is_reference and head != ">":
raise ValueError("Missing '>' for reference type name in browse path.")
raise ValueError("Missing closing '>' for reference type name in browse path.")

if len(name) == 0:
if is_reference:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_relative_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ def test_relative_path_with_invalid_format():
with pytest.raises(ValueError):
RelativePath.from_string("/1:Boiler&") # '&' is appeared without a follwing character.

with pytest.raises(ValueError):
RelativePath.from_string("/1:Boiler&Output") # '&' is followed by a non-reserved char.

with pytest.raises(ValueError):
RelativePath.from_string("<0:HasChild") # Closing delimiter '>' is missing.

Expand Down

0 comments on commit 6f52e15

Please sign in to comment.