From 65542b5fac4e46707c37a47e95b459454076b1eb Mon Sep 17 00:00:00 2001 From: Aevann Date: Sun, 19 Mar 2023 19:53:33 +0200 Subject: [PATCH] dont strip poll options --- files/helpers/actions.py | 2 +- files/helpers/sanitize.py | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/files/helpers/actions.py b/files/helpers/actions.py index 7ea26a628..cd8e4434f 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -524,7 +524,7 @@ def process_poll_options(v:User, target:Union[Submission, Comment]): else: cls = CommentOption - body_html=filter_emojis_only(body) + body_html=filter_emojis_only(body, strip=False) #dont strip cuz ppl sometimes leave spaces before && or after it, which breaks the replacing logic existing = g.db.query(cls).filter_by( parent_id=target.id, diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 8343f3c0f..f54195987 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -546,13 +546,11 @@ def allowed_attributes_emojis(tag, name, value): @with_sigalrm_timeout(1) -def filter_emojis_only(title, golden=True, count_emojis=False, graceful=False, torture=False): - title = title.strip() - +def filter_emojis_only(title, golden=True, count_emojis=False, graceful=False, torture=False, strip=True): if torture: title = torture_ap(title, g.v.username) - title = title.replace('‎','').replace('​','').replace("\ufeff", "").replace("𒐪","").replace("\n", "").replace("\r", "").replace("\t", "").replace('<','<').replace('>','>').replace("﷽","").strip() + title = title.replace('‎','').replace('​','').replace("\ufeff", "").replace("𒐪","").replace("\n", "").replace("\r", "").replace("\t", "").replace('<','<').replace('>','>').replace("﷽","") emojis_used = set() @@ -565,7 +563,10 @@ def filter_emojis_only(title, golden=True, count_emojis=False, graceful=False, t title = strikethrough_regex.sub(r'\1\2', title) - title = bleach.clean(title, tags=['img','del','span'], attributes=allowed_attributes_emojis, protocols=['http','https']).replace('\n','').strip() + title = bleach.clean(title, tags=['img','del','span'], attributes=allowed_attributes_emojis, protocols=['http','https']).replace('\n','') + + if strip: + title = title.strip() if len(title) > POST_TITLE_HTML_LENGTH_LIMIT and not graceful: abort(400) else: return title