Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions docs/api/model.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,17 @@ def preprocess_with_cdata(cls, content: str) -> str:
return f"<{field_name}{tag_attrs}>{content}</{field_name}>"

fields_pattern = "|".join(re.escape(field_name) for field_name in field_map)
pattern = f"<({fields_pattern})((?:[^>]*?)?)>(.*?)</\\1>"
pattern = f"<({fields_pattern})((?:\\s[^>]*?)?)>(.*?)</\\1>"

return re.sub(pattern, wrap_with_cdata, content, flags=re.DOTALL)
updated = re.sub(pattern, wrap_with_cdata, content, flags=re.DOTALL)

# If our updates created invalid XML, discard them
try:
ET.fromstring(updated) # noqa: S314 # nosec
except ET.ParseError:
return content

return updated
```


Expand Down
12 changes: 10 additions & 2 deletions rigging/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,17 @@ def wrap_with_cdata(match: re.Match[str]) -> str:
return f"<{field_name}{tag_attrs}>{content}</{field_name}>"

fields_pattern = "|".join(re.escape(field_name) for field_name in field_map)
pattern = f"<({fields_pattern})((?:[^>]*?)?)>(.*?)</\\1>"
pattern = f"<({fields_pattern})((?:\\s[^>]*?)?)>(.*?)</\\1>"

return re.sub(pattern, wrap_with_cdata, content, flags=re.DOTALL)
updated = re.sub(pattern, wrap_with_cdata, content, flags=re.DOTALL)

# If our updates created invalid XML, discard them
try:
ET.fromstring(updated) # noqa: S314 # nosec
except ET.ParseError:
return content

return updated

# Attempt to extract this object from an arbitrary string
# which may contain other XML elements or text, returns
Expand Down
Loading