diff --git a/files/helpers/const.py b/files/helpers/const.py index 35cb61a71..eb82809fe 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -679,7 +679,7 @@ imgur_regex = re.compile('(https://i\.imgur\.com/([^_]*?))\.(jpg|png|jpeg|webp)( reddit_regex = re.compile('(^|\s|

)\/?((r|u)\/(\w|-){3,25})', flags=re.A) sub_regex = re.compile('(^|\s|

)\/?(s\/(\w|-){3,25})', flags=re.A) youtube_regex = re.compile('" target="_blank">(https://youtube\.com/watch\?v\=(.*?))(?!)', flags=re.A) -strikethrough_regex = re.compile('~~(.*?)~~', flags=re.A) +strikethrough_regex = re.compile('~{1,2}([^~]+)~{1,2}', flags=re.A) emoji_regex = re.compile("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", flags=re.A) emoji_regex2 = re.compile('(?\1', sanitized) + sanitized = sanitized.replace("\ufeff", "").replace("𒐪","").replace("","").replace('‎','') if alert: diff --git a/files/routes/comments.py b/files/routes/comments.py index 2f42a8d8c..22fc9802e 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -213,9 +213,11 @@ def api_comment(v): if v.marseyawarded and parent_post.id not in (37696,37697,37749,37833,37838): if not marsey_regex.fullmatch(body): return {"error":"You can only type marseys!"}, 403 - if v.longpost and len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403 - elif v.bird and len(body) > 140 and parent_post.id not in (37696,37697,37749,37833,37838): - return {"error":"You have to type less than 140 characters!"}, 403 + if parent_post.id not in (37696,37697,37749,37833,37838): + if v.longpost and (len(body) < 280 or ' [](' in body or body.startswith('[](')): + return {"error":"You have to type more than 280 characters!"}, 403 + elif v.bird and len(body) > 140: + return {"error":"You have to type less than 140 characters!"}, 403 if not body and not request.files.get('file'): return {"error":"You need to actually write something!"}, 400 @@ -339,13 +341,6 @@ def api_comment(v): body_html = sanitize(body, comment=True) - if parent_post.id not in (37696,37697,37749,37833,37838): - if v.longpost: - if len(body) < 280 or ' [](' in body or body.startswith('[]('): - return {"error":"You have to type more than 280 characters!"}, 403 - elif v.bird: - if len(body) > 140 : return {"error":"You have to type less than 140 characters!"}, 403 - bans = filter_comment_html(body_html) if bans: @@ -725,8 +720,10 @@ def edit_comment(cid, v): if v.marseyawarded and not marsey_regex.fullmatch(body): return {"error":"You can only type marseys!"}, 403 - if v.longpost and len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403 - elif v.bird and len(body) > 140: return {"error":"You have to type less than 140 characters!"}, 403 + if v.longpost and (len(body) < 280 or ' [](' in body or body.startswith('[](')): + return {"error":"You have to type more than 280 characters!"}, 403 + elif v.bird and len(body) > 140: + return {"error":"You have to type less than 140 characters!"}, 403 body = image_regex.sub(r'![](\1)', body) @@ -761,11 +758,6 @@ def edit_comment(cid, v): body_html = sanitize(body, edit=True) - if v.longpost: - if len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403 - elif v.bird: - if len(body) > 140 : return {"error":"You have to type less than 140 characters!"}, 403 - bans = filter_comment_html(body_html) if bans: diff --git a/files/routes/posts.py b/files/routes/posts.py index 82c9a5af3..2573dd675 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -467,8 +467,10 @@ def edit_post(pid, v): if v.marseyawarded and (not marsey_regex.fullmatch(title) or body and not marsey_regex.fullmatch(body)): return {"error":"You can only type marseys!"}, 403 - if v.longpost and len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403 - elif v.bird and len(body) > 140: return {"error":"You have to type less than 140 characters!"}, 403 + if v.longpost and (len(body) < 280 or ' [](' in body or body.startswith('[](')): + return {"error":"You have to type more than 280 characters!"}, 403 + elif v.bird and len(body) > 140: + return {"error":"You have to type less than 140 characters!"}, 403 if title != p.title: if v.agendaposter and not v.marseyawarded: title = torture_ap(title, v.username) @@ -536,11 +538,6 @@ def edit_post(pid, v): p.body = body - if v.longpost: - if len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403 - elif v.bird: - if len(body) > 140 : return {"error":"You have to type less than 140 characters!"}, 403 - if len(body_html) > 40000: return {"error":"Submission body too long!"}, 400 p.body_html = body_html @@ -849,10 +846,10 @@ def submit_post(v, sub=None): title_html = filter_emojis_only(title, graceful=True) if len(title_html) > 1500: return error("Rendered title is too big!") - if v.longpost: - if len(body) < 280 or ' [](' in body or body.startswith('[]('): return error("You have to type more than 280 characters!") - elif v.bird: - if len(body) > 140 : return error("You have to type less than 140 characters!") + if v.longpost and (len(body) < 280 or ' [](' in body or body.startswith('[](')): + return {"error":"You have to type more than 280 characters!"}, 403 + elif v.bird and len(body) > 140: + return {"error":"You have to type less than 140 characters!"}, 403 embed = None @@ -946,9 +943,6 @@ def submit_post(v, sub=None): if v.marseyawarded and (not marsey_regex.fullmatch(title) or body and not marsey_regex.fullmatch(body)): return error("You can only type marseys!") - if v.longpost and len(body) < 280 or ' [](' in body or body.startswith('[]('): return error("You have to type more than 280 characters!") - elif v.bird and len(body) > 140: return error("You have to type less than 140 characters!") - dup = g.db.query(Submission).filter( Submission.author_id == v.id, Submission.deleted_utc == 0, @@ -1052,11 +1046,6 @@ def submit_post(v, sub=None): body_html = sanitize(body) - if v.longpost: - if len(body) < 280 or ' [](' in body or body.startswith('[]('): return error("You have to type more than 280 characters!") - elif v.bird: - if len(body) > 140 : return error("You have to type less than 140 characters!") - if len(body_html) > 40000: return error("Submission body too long!") bans = filter_comment_html(body_html)