From cc9e007581b7d7c4a76a4c7548984a4024540f6c Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 25 Nov 2022 23:33:38 +0200 Subject: [PATCH] limit polls to 10 options to prevent spam --- files/routes/comments.py | 8 ++++---- files/routes/posts.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/files/routes/comments.py b/files/routes/comments.py index 5dc148383..7c71fc6b6 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -132,12 +132,12 @@ def comment(v): abort(403, "You can't reply to users who have blocked you or users that you have blocked.") options = [] - for i in poll_regex.finditer(body): + for i in list(poll_regex.finditer(body))[:10]: options.append(i.group(1)) body = body.replace(i.group(0), "") choices = [] - for i in choice_regex.finditer(body): + for i in list(choice_regex.finditer(body))[:10]: choices.append(i.group(1)) body = body.replace(i.group(0), "") @@ -390,7 +390,7 @@ def edit_comment(cid, v): elif v.bird and len(body) > 140: abort(403, "You have to type less than 140 characters!") - for i in poll_regex.finditer(body): + for i in list(poll_regex.finditer(body))[:10]: body = body.replace(i.group(0), "") body_html = filter_emojis_only(i.group(1)) if len(body_html) > 500: abort(400, "Poll option too long!") @@ -401,7 +401,7 @@ def edit_comment(cid, v): ) g.db.add(option) - for i in choice_regex.finditer(body): + for i in list(choice_regex.finditer(body))[:10]: body = body.replace(i.group(0), "") body_html = filter_emojis_only(i.group(1)) if len(body_html) > 500: abort(400, "Poll option too long!") diff --git a/files/routes/posts.py b/files/routes/posts.py index a6068efbd..987eabdad 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -360,7 +360,7 @@ def edit_post(pid, v): ) g.db.add(bet) - for i in poll_regex.finditer(body): + for i in list(poll_regex.finditer(body))[:10]: body = body.replace(i.group(0), "") body_html = filter_emojis_only(i.group(1)) if len(body_html) > 500: abort(400, "Poll option too long!") @@ -371,7 +371,7 @@ def edit_post(pid, v): ) g.db.add(option) - for i in choice_regex.finditer(body): + for i in list(choice_regex.finditer(body))[:10]: body = body.replace(i.group(0), "") body_html = filter_emojis_only(i.group(1)) if len(body_html) > 500: abort(400, "Poll option too long!") @@ -754,12 +754,12 @@ def submit_post(v, sub=None): body = body.replace(i.group(0), "") options = [] - for i in poll_regex.finditer(body): + for i in list(poll_regex.finditer(body))[:10]: options.append(i.group(1)) body = body.replace(i.group(0), "") choices = [] - for i in choice_regex.finditer(body): + for i in list(choice_regex.finditer(body))[:10]: choices.append(i.group(1)) body = body.replace(i.group(0), "")