Coverage for polar/kit/html.py: 0%
7 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 16:17 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 16:17 +0000
1import re
3RE_HTML_TAG = re.compile(r"<[^>]*>")
6def dangerously_strip_tags(html_input: str) -> str:
7 """
8 This function TRIES to remove HTML tags from a string, however
9 it's is highly likely that an attacker would be able to still
10 end up with dangerous HTML in the returned string.
12 Therefore use DO NOT use this not as a sanitizer, but rather for making
13 HTML that is known to be safe into plaintext.
14 """
16 result = re.sub(RE_HTML_TAG, "", html_input)
18 # Replace any leftover "<" and ">"s with their HTML entities
19 result = result.replace("<", "<")
20 result = result.replace(">", ">")
22 return result