Add UTF-8 decoding utility and corresponding unit tests

- Introduced a new utility function `decode_utf` in `utils.py` to decode escaped UTF-8 descriptions.
- Updated unit tests in `test_units.py` to include tests for the `decode_utf` function, covering plain text and escaped UTF-8 scenarios.
- Refactored existing tests to streamline the usage of the `expand_vlan_range` function.
This commit is contained in:
IluaAir
2026-06-06 13:55:01 +03:00
parent f446ae52e7
commit 229bef99f6
2 changed files with 25 additions and 16 deletions

View File

@@ -23,3 +23,17 @@ def expand_vlan_range(value: str | list[str]) -> list[str]:
else:
result.append(part)
return result
def decode_utf(text: str):
"""Decode escaped UTF-8 descriptions."""
if "\\x" in text:
desc = text.strip('"')
decoded = (
desc.encode("utf-8")
.decode("unicode_escape")
.encode("latin1")
.decode("utf-8")
)
return decoded
return text