Skip to content

Commit b89faf5

Browse files
committed
feat: Remove possible incompatible characters for XML compatibility
1 parent fd0941a commit b89faf5

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

hmdriver2/_xpath.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3+
import re
34
from typing import Dict
45
from lxml import etree
56
from functools import cached_property
@@ -37,6 +38,8 @@ def __call__(self, xpath: str) -> '_XMLElement':
3738
def _json2xml(hierarchy: Dict) -> etree.Element:
3839
attributes = hierarchy.get("attributes", {})
3940
tag = attributes.get("type", "orgRoot") or "orgRoot"
41+
# Clean the "text" attribute to be compatible with XML format
42+
attributes["text"] = re.sub(u"[^\u0020-\uD7FF\u0009\u000A\u000D\uE000-\uFFFD\U00010000-\U0010FFFF]+", "", attributes.get("text", ""))
4043
xml = etree.Element(tag, attrib=attributes)
4144

4245
children = hierarchy.get("children", [])

0 commit comments

Comments
 (0)