From 883c96a8303f41b95b308341f989ff250de5fd7d Mon Sep 17 00:00:00 2001 From: Aevann Date: Sat, 24 Jun 2023 21:54:36 +0300 Subject: [PATCH] fix 500 erro --- files/classes/comment.py | 6 +++--- files/helpers/sanitize.py | 8 +++++--- files/routes/awards.py | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/files/classes/comment.py b/files/classes/comment.py index 74490c72a..6da2c33fc 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -92,10 +92,10 @@ def add_options(self, body, v): elif o.exclusive: s = '&&' else: s = '$$' - if not o.created_utc or o.created_utc < 1677622270: + if f'{s}{o.body_html}{s}' in body: + body = body.replace(f'{s}{o.body_html}{s}', option_body, 1) + elif not o.created_utc or o.created_utc < 1677622270: body += option_body - else: - body = re.sub(rf'{s} *{o.body_html} *{s}', option_body, body, count=1, flags=re.I) return body diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index c8e6afcce..9aa958c47 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -278,19 +278,18 @@ def remove_cuniform(sanitized:Optional[str]) -> str: sanitized = sanitized.replace('\u200e','').replace('\u200b','').replace('\u202e','').replace("\ufeff", "") sanitized = sanitized.replace("𒐪","").replace("𒐫","").replace("﷽","") sanitized = sanitized.replace("\r\n", "\n") - sanitized = sanitized.strip() return sanitized def sanitize_raw_title(sanitized:Optional[str]) -> str: if not sanitized: return "" sanitized = sanitized.replace("\r","").replace("\n", "") - sanitized = remove_cuniform(sanitized) + sanitized = remove_cuniform(sanitized).strip() return sanitized[:POST_TITLE_LENGTH_LIMIT] def sanitize_raw_body(sanitized:Optional[str], is_post:bool) -> str: if not sanitized: return "" sanitized = html_comment_regex.sub('', sanitized) - sanitized = remove_cuniform(sanitized) + sanitized = remove_cuniform(sanitized).strip() return sanitized[:POST_BODY_LENGTH_LIMIT(g.v) if is_post else COMMENT_BODY_LENGTH_LIMIT] @@ -612,6 +611,9 @@ def filter_emojis_only(title, golden=True, count_emojis=False, graceful=False, s title = remove_cuniform(title) + if strip: + title = title.strip() + emojis_used = set() title = render_emoji(title, emoji_regex3, golden, emojis_used) diff --git a/files/routes/awards.py b/files/routes/awards.py index 56dcd474d..9b58e0dcd 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -396,7 +396,7 @@ def award_thing(v, thing_type, id): elif kind == "flairlock": new_name = note[:100] - new_name = remove_cuniform(new_name) + new_name = remove_cuniform(new_name).strip() if not new_name and author.flairchanged: author.flairchanged += 86400 else: