From 04a1b875efbe4d3dce282cbb53eaf9f86dfb9d35 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 4 Feb 2022 11:15:59 +0200 Subject: [PATCH] sfd --- files/classes/submission.py | 4 ++-- files/helpers/alerts.py | 2 +- files/helpers/const.py | 6 +++--- files/helpers/sanitize.py | 20 ++++++++++---------- files/routes/comments.py | 16 ++++++++-------- files/routes/posts.py | 26 +++++++++++++------------- files/routes/search.py | 2 +- files/routes/settings.py | 8 ++++---- 8 files changed, 42 insertions(+), 42 deletions(-) diff --git a/files/classes/submission.py b/files/classes/submission.py index 758481c49c..2858838121 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -196,9 +196,9 @@ class Submission(Base): output = self.title.lower() - output = re.sub('&\w{2,3};', '', output, flags=re.A) + output = re.sub('&\w{2,3};', '', output, re.A) - output = [re.sub('\W', '', word, flags=re.A) for word in output.split()] + output = [re.sub('\W', '', word, re.A) for word in output.split()] output = [x for x in output if x][:6] output = '-'.join(output) diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index 9ac3f4a671..24c41a66c4 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -82,7 +82,7 @@ def NOTIFY_USERS2(text, v): if id == 0: continue if word in text.lower() and id not in notify_users and v.id != id: notify_users.add(id) - for i in re.finditer("(^|\s|\n)@((\w|-){1,25})", text, flags=re.A): + for i in re.finditer("(^|\s|\n)@((\w|-){1,25})", text, re.A): user = get_user(i.group(2), graceful=True) if user and not v.any_block_exists(user): notify_users.add(user.id) diff --git a/files/helpers/const.py b/files/helpers/const.py index b6ce385a9e..c1e2a355c9 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -100,7 +100,7 @@ SLURS = { } single_words = "|".join([slur.lower() for slur in SLURS.keys()]) -SLUR_REGEX = re.compile(rf"(?i)((?<=\s|>)|^)({single_words})((?=[\s<,.]|s[\s<,.])|$)", flags=re.A) +SLUR_REGEX = re.compile(rf"(?i)((?<=\s|>)|^)({single_words})((?=[\s<,.]|s[\s<,.])|$)", re.A) def sub_matcher(match: re.Match): return SLURS[match.group(0).lower()] @@ -112,8 +112,8 @@ def censor_slurs(body: str, logged_user): def torture_ap(body, username): body = SLUR_REGEX.sub(sub_matcher, body) for k, l in AJ_REPLACEMENTS.items(): body = body.replace(k, l) - body = re.sub('(^|\s|\n)(i|me) ', rf'\1@{username} ', body, flags=re.I|re.A) - body = re.sub("(^|\s|\n)i'm ", rf'\1@{username} is ', body, flags=re.I|re.A) + body = re.sub('(^|\s|\n)(i|me) ', rf'\1@{username} ', body, re.I|re.A) + body = re.sub("(^|\s|\n)i'm ", rf'\1@{username} is ', body, re.I|re.A) return body diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 43d0d48b2e..550ccb063f 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -105,14 +105,14 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): sanitized = sanitized.replace("\ufeff", "").replace("𒐪","").replace("@((\w|-){1,25})", sanitized, flags=re.A): + for i in re.finditer("

@((\w|-){1,25})", sanitized, re.A): u = get_user(i.group(1), graceful=True) if u: sanitized = sanitized.replace(i.group(0), f'''

@{u.username}'s profile picture@{u.username}''', 1) else: - sanitized = re.sub('(^|\s|\n|

)\/?((r|u)\/(\w|-){3,25})', r'\1\2', sanitized, flags=re.A) + sanitized = re.sub('(^|\s|\n|

)\/?((r|u)\/(\w|-){3,25})', r'\1\2', sanitized, re.A) - for i in re.finditer('(^|\s|\n|

)@((\w|-){1,25})', sanitized, flags=re.A): + for i in re.finditer('(^|\s|\n|

)@((\w|-){1,25})', sanitized, re.A): u = get_user(i.group(2), graceful=True) if u and (not g.v.any_block_exists(u) or g.v.admin_level > 1): @@ -167,7 +167,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): tag["target"] = "_blank" tag["rel"] = "nofollow noopener noreferrer" - if re.match("https?://\S+", str(tag.string), flags=re.A): + if re.match("https?://\S+", str(tag.string), re.A): try: tag.string = tag["href"] except: tag.string = "" @@ -178,7 +178,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): if comment: marseys_used = set() - emojis = list(re.finditer("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", sanitized, flags=re.A)) + emojis = list(re.finditer("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", sanitized, re.A)) if len(emojis) > 20: edit = True for i in emojis: old = i.group(0) @@ -202,7 +202,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): if not edit and random() < 0.005 and 'marsey' in emoji: classes += ' golden' if path.isfile(f'files/assets/images/emojis/{remoji}.webp'): - new = re.sub(f'(?', new, flags=re.I) + new = re.sub(f'(?', new, re.I) if comment: marseys_used.add(emoji) sanitized = sanitized.replace(old, new) @@ -216,13 +216,13 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): classes = 'emoji mirrored' if not edit and random() < 0.005 and 'marsey' in emoji: classes += ' golden' if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): - sanitized = re.sub(f'(?', sanitized, flags=re.I) + sanitized = re.sub(f'(?', sanitized, re.I) if comment: marseys_used.add(emoji) elif path.isfile(f'files/assets/images/emojis/{emoji}.webp'): classes = 'emoji' if not edit and random() < 0.005 and 'marsey' in emoji: classes += ' golden' - sanitized = re.sub(f'(?', sanitized, flags=re.I) + sanitized = re.sub(f'(?', sanitized, re.I) if comment: marseys_used.add(emoji) sanitized = sanitized.replace("https://youtu.be/", "https://youtube.com/watch?v=").replace("https://music.youtube.com/watch?v=", "https://youtube.com/watch?v=").replace("https://open.spotify.com/", "https://open.spotify.com/embed/").replace("https://streamable.com/", "https://streamable.com/e/").replace("https://youtube.com/shorts/", "https://youtube.com/watch?v=").replace("https://mobile.twitter", "https://twitter").replace("https://m.facebook", "https://facebook").replace("m.wikipedia.org", "wikipedia.org").replace("https://m.youtube", "https://youtube").replace("https://www.youtube", "https://youtube") @@ -282,12 +282,12 @@ def filter_emojis_only(title, edit=False): classes = 'emoji mirrored' if not edit and random() < 0.005 and 'marsey' in emoji: classes += ' golden' if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): - title = re.sub(f'(?', title, flags=re.I) + title = re.sub(f'(?', title, re.I) elif path.isfile(f'files/assets/images/emojis/{emoji}.webp'): classes = 'emoji' if not edit and random() < 0.005 and 'marsey' in emoji: classes += ' golden' - title = re.sub(f'(?', title, flags=re.I) + title = re.sub(f'(?', title, re.I) if len(title) > 1500: abort(400) else: return title \ No newline at end of file diff --git a/files/routes/comments.py b/files/routes/comments.py index 018d9806a0..28a2279680 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -165,7 +165,7 @@ def api_comment(v): f.write('\n{[para]}\n' + body) if v.marseyawarded and parent_post.id not in (37696,37697,37749,37833,37838): - marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, flags=re.A)) + marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, re.A)) if len(marregex) == 0: 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 @@ -174,11 +174,11 @@ def api_comment(v): if not body and not request.files.get('file'): return {"error":"You need to actually write something!"}, 400 - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', body, re.M|re.A): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') options = [] - for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, flags=re.A): + for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, re.A): options.append(i.group(1)) body = body.replace(i.group(0), "") @@ -249,7 +249,7 @@ def api_comment(v): body_html = sanitize(body, comment=True) - if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, flags=re.A))): return {"error":"You can only type marseys!"}, 403 + if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, re.A))): return {"error":"You can only type marseys!"}, 403 if parent_post.id not in (37696,37697,37749,37833,37838): if v.longpost: @@ -654,20 +654,20 @@ def edit_comment(cid, v): if body != c.body or request.files.get("file") and request.headers.get("cf-ipcountry") != "T1": if v.marseyawarded: - marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, flags=re.A)) + marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, re.A)) if len(marregex) == 0: 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 - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', body, re.M|re.A): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') if v.agendaposter and not v.marseyawarded: body = torture_ap(body, v.username) if not c.options: - for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, flags=re.A): + for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, re.A): body = body.replace(i.group(0), "") c_option = Comment(author_id=AUTOPOLLER_ID, parent_submission=c.parent_submission, @@ -681,7 +681,7 @@ def edit_comment(cid, v): body_html = sanitize(body, edit=True) - if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, flags=re.A))): return {"error":"You can only type marseys!"}, 403 + if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, re.A))): return {"error":"You can only type marseys!"}, 403 if v.longpost: if len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403 diff --git a/files/routes/posts.py b/files/routes/posts.py index 2ed30fe54c..1cc31c177d 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -415,10 +415,10 @@ def edit_post(pid, v): if len(body) > 20000: return {"error":"Character limit is 20000!"}, 403 if v.marseyawarded: - marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", title, flags=re.A)) + marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", title, re.A)) if len(marregex) == 0: return {"error":"You can only type marseys!"}, 403 if body: - marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, flags=re.A)) + marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, re.A)) if len(marregex) == 0: 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 @@ -428,7 +428,7 @@ def edit_post(pid, v): if v.agendaposter and not v.marseyawarded: title = torture_ap(title, v.username) title_html = filter_emojis_only(title, edit=True) - if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', title_html, flags=re.A))): return {"error":"You can only type marseys!"}, 403 + if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', title_html, re.A))): return {"error":"You can only type marseys!"}, 403 p.title = title[:500] p.title_html = title_html @@ -449,13 +449,13 @@ def edit_post(pid, v): else: return {"error": "Image/Video files only"}, 400 if body != p.body: - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', body, re.M|re.A): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') if v.agendaposter and not v.marseyawarded: body = torture_ap(body, v.username) if not p.options.count(): - for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, flags=re.A): + for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, re.A): body = body.replace(i.group(0), "") c = Comment(author_id=AUTOPOLLER_ID, parent_submission=p.id, @@ -478,7 +478,7 @@ def edit_post(pid, v): return {"error": reason}, 403 p.body = body - if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, flags=re.A))): return {"error":"You can only type marseys!"}, 40 + if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, re.A))): return {"error":"You can only type marseys!"}, 40 if v.longpost: if len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403 @@ -769,7 +769,7 @@ def submit_post(v): title_html = filter_emojis_only(title) body = request.values.get("body", "").strip().replace('‎','') - if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', title_html, flags=re.A))): return {"error":"You can only type marseys!"}, 40 + if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', title_html, re.A))): return {"error":"You can only type marseys!"}, 40 if v.longpost: if len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403 @@ -859,10 +859,10 @@ def submit_post(v): else: render_template("submit.html", v=v, error="500 character limit for titles.", title=title[:500], url=url, body=request.values.get("body", "")), 400 if v.marseyawarded: - marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", title, flags=re.A)) + marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", title, re.A)) if len(marregex) == 0: return {"error":"You can only type marseys!"}, 403 if body: - marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, flags=re.A)) + marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, re.A)) if len(marregex) == 0: 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 @@ -932,17 +932,17 @@ def submit_post(v): if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error":"2048 character limit for URLs."}, 400 return render_template("submit.html", v=v, error="2048 character limit for URLs.", title=title, url=url,body=request.values.get("body", "")), 400 - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', body, re.M|re.A): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') if v and v.admin_level > 2: bet_options = [] - for i in re.finditer('\s*\$\$\$([^\$\n]+)\$\$\$\s*', body, flags=re.A): + for i in re.finditer('\s*\$\$\$([^\$\n]+)\$\$\$\s*', body, re.A): bet_options.append(i.group(1)) body = body.replace(i.group(0), "") options = [] - for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, flags=re.A): + for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, re.A): options.append(i.group(1)) body = body.replace(i.group(0), "") @@ -971,7 +971,7 @@ def submit_post(v): body_html = sanitize(body) - if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, flags=re.A))): return {"error":"You can only type marseys!"}, 400 + if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, re.A))): return {"error":"You can only type marseys!"}, 400 if v.longpost: if len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403 diff --git a/files/routes/search.py b/files/routes/search.py index 0efbd0054f..f4918a40b8 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -5,7 +5,7 @@ from flask import * from files.__main__ import app -query_regex=re.compile("(\w+):(\S+)", flags=re.A) +query_regex=re.compile("(\w+):(\S+)", re.A) valid_params=[ 'author', 'domain', diff --git a/files/routes/settings.py b/files/routes/settings.py index 128c935b61..31c88ae2f0 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -142,7 +142,7 @@ def settings_profile_post(v): elif (v.patron or v.id == MOOSE_ID) and request.values.get("sig"): sig = request.values.get("sig")[:200] - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', sig, re.MULTILINE): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', sig, re.M|re.A): if "wikipedia" not in i.group(1): sig = sig.replace(i.group(1), f'![]({i.group(1)})') sig_html = sanitize(sig) @@ -176,7 +176,7 @@ def settings_profile_post(v): elif request.values.get("friends"): friends = request.values.get("friends")[:500] - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', friends, re.MULTILINE): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', friends, re.M|re.A): if "wikipedia" not in i.group(1): friends = friends.replace(i.group(1), f'![]({i.group(1)})') friends_html = sanitize(friends) @@ -213,7 +213,7 @@ def settings_profile_post(v): elif request.values.get("enemies"): enemies = request.values.get("enemies")[:500] - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', enemies, re.MULTILINE): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', enemies, re.M|re.A): if "wikipedia" not in i.group(1): enemies = enemies.replace(i.group(1), f'![]({i.group(1)})') enemies_html = sanitize(enemies) @@ -250,7 +250,7 @@ def settings_profile_post(v): elif request.values.get("bio") or request.files.get('file') and request.headers.get("cf-ipcountry") != "T1": bio = request.values.get("bio")[:1500] - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', bio, re.MULTILINE): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', bio, re.M|re.A): if "wikipedia" not in i.group(1): bio = bio.replace(i.group(1), f'![]({i.group(1)})') if request.files.get('file'):