sanitize: strip out html comments

they're unnecessary and never get rendered
remotes/1693176582716663532/tmp_refs/heads/watchparty
justcool393 2022-10-20 18:06:55 -05:00
parent 360cff7e8f
commit 578e1896fd
2 changed files with 3 additions and 0 deletions

View File

@ -27,6 +27,8 @@ poll_regex = re.compile("\s*\$\$([^\$\n]+)\$\$\s*", flags=re.A)
bet_regex = re.compile("\s*\$\$\$([^\$\n]+)\$\$\$\s*", flags=re.A)
choice_regex = re.compile("\s*&&([^\$\n]+)&&\s*", flags=re.A)
html_comment_regex = re.compile("<!--.*-->", flags=re.A)
title_regex = re.compile("[^\w ]", flags=re.A)
based_regex = re.compile("based and (.{1,20}?)(-| )pilled", flags=re.I|re.A)

View File

@ -197,6 +197,7 @@ def sanitize_raw_title(sanitized):
def sanitize_raw_body(sanitized, is_post):
if not sanitized: return ""
sanitized = html_comment_regex.sub('', sanitized)
sanitized = sanitized.replace('\u200e','').replace('\u200b','').replace("\ufeff", "").replace("\r\n", "\n")
sanitized = sanitized.strip()
return sanitized[:POST_BODY_LENGTH_LIMIT if is_post else COMMENT_BODY_LENGTH_LIMIT]