You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
which has the double-quote escaped in the regex pattern.
The double-quote in the regex pattern in the XML is valid so the issue is the dataclass file is generated using double-quotes around strings but doesn't have any logic to escape double-quotes in regex patterns. However, double-quotes are properly escaped for all other strings. This issue is only because of the special if for patterns located here
##Proposed Change
Using the existing behavior of text.escape_string wouldn't be valid for regexes since we don't want to escape other characters. We only need to escape double-quotes in the regex. Also, we shouldn't escape already escaped double-quotes.
I can create a PR where I add a simple regex sub like this:
if key == "pattern":
value = re.sub(r'([^\\])\"', r'\1\\"', data)
return f'r"{value}"'
so we only escape double-quotes if they aren't already escaped.
Let me know if you like that solution and I'll create a PR.
The text was updated successfully, but these errors were encountered:
Unexpected Behavior
If there is a pattern restriction in an XML file similar to this
xsdata will generate a field with an unescaped quote character in the metadata dict which looks like the following:
This terminates the regex string early and causes a syntax error
Expected Behavior
The expected behavior should produce this:
which has the double-quote escaped in the regex pattern.
The double-quote in the regex pattern in the XML is valid so the issue is the dataclass file is generated using double-quotes around strings but doesn't have any logic to escape double-quotes in regex patterns. However, double-quotes are properly escaped for all other strings. This issue is only because of the special
if
for patterns located herehttps://github.com/tefra/xsdata/blob/master/xsdata/formats/dataclass/filters.py#L433
##Proposed Change
Using the existing behavior of
text.escape_string
wouldn't be valid for regexes since we don't want to escape other characters. We only need to escape double-quotes in the regex. Also, we shouldn't escape already escaped double-quotes.I can create a PR where I add a simple regex sub like this:
so we only escape double-quotes if they aren't already escaped.
Let me know if you like that solution and I'll create a PR.
The text was updated successfully, but these errors were encountered: