fix escape_all for Union types with strings
This commit is contained in:
parent
a7c5431ec1
commit
12c08f1026
1 changed files with 1 additions and 1 deletions
|
|
@ -314,7 +314,7 @@ class ElementParser(HTMLParser):
|
||||||
def escape_all(dc, escape: Callable[[str], str] = html_escape) -> None:
|
def escape_all(dc, escape: Callable[[str], str] = html_escape) -> None:
|
||||||
"""Patch a dataclass to escape all strings."""
|
"""Patch a dataclass to escape all strings."""
|
||||||
for f in fields(dc):
|
for f in fields(dc):
|
||||||
if f.type is str:
|
if type(getattr(dc, f.name)) is str:
|
||||||
setattr(dc, f.name, escape(getattr(dc, f.name)))
|
setattr(dc, f.name, escape(getattr(dc, f.name)))
|
||||||
elif get_origin(f.type) is list and get_args(f.type)[0] is str:
|
elif get_origin(f.type) is list and get_args(f.type)[0] is str:
|
||||||
setattr(dc, f.name, [escape(x) for x in getattr(dc, f.name)])
|
setattr(dc, f.name, [escape(x) for x in getattr(dc, f.name)])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue