From 12c08f1026f0d7d965aec23ea5b70cf00140ddd1 Mon Sep 17 00:00:00 2001 From: ducklet Date: Tue, 10 Nov 2020 21:35:06 +0100 Subject: [PATCH] fix escape_all for Union types with strings --- hotdog/functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hotdog/functions.py b/hotdog/functions.py index 8b96471..179b235 100644 --- a/hotdog/functions.py +++ b/hotdog/functions.py @@ -314,7 +314,7 @@ class ElementParser(HTMLParser): def escape_all(dc, escape: Callable[[str], str] = html_escape) -> None: """Patch a dataclass to escape all strings.""" 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))) 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)])