Skip to content

Commit

Permalink
html escape attribute keys also
Browse files Browse the repository at this point in the history
  • Loading branch information
sayanarijit committed Feb 12, 2024
1 parent 86b85d5 commit 639c831
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions tiptapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,16 @@ def escape_values_recursive(node):
html_key = "html" # key to look for html content
if isinstance(node, dict):
for k, v in node.items():
if k == html_key:
esc_k = escape(k)
if k != esc_k:
node[esc_k] = node.pop(k)
if esc_k == html_key:
# Allow only iframe tag
p = IFrameParser()
p.feed(v)
node[k] = p.iframe
node[esc_k] = p.iframe
else:
node[k] = escape_values_recursive(v)
node[esc_k] = escape_values_recursive(v)
elif isinstance(node, list):
for i, v in enumerate(node):
node[i] = escape_values_recursive(v)
Expand Down
5 changes: 4 additions & 1 deletion tiptapy/macros.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pkgutil
from html import escape
from string import Template
from urllib.parse import urlparse

Expand Down Expand Up @@ -31,7 +32,9 @@ def handle_links(attrs):
):
attrs["target"] = "_blank"
attrs["rel"] = "noopener nofollow"
retval = " ".join(f'{k}="{v}"' for k, v in attrs.items() if v is not None)
retval = " ".join(
f'{escape(k)}="{escape(v)}"' for k, v in attrs.items() if v is not None
)
return retval

return handle_links
Expand Down

0 comments on commit 639c831

Please sign in to comment.