diff --git a/files/classes/comment.py b/files/classes/comment.py index 6e6cca65e..c8ba86bc2 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -341,7 +341,7 @@ class Comment(Base): if v.nitter and not '/i/' in body: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net") if v and v.controversial: - for i in re.finditer('(/comments/.*?)"', body): + for i in re.finditer('(/comments/.*?)"', body, flags=re.A): url = i.group(1) p = urlparse(url).query p = parse_qs(p) @@ -402,7 +402,7 @@ class Comment(Base): if v and v.nitter and not '/i/' in body: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net") if v and v.controversial: - for i in re.finditer('(/comments/.*?)"', body): + for i in re.finditer('(/comments/.*?)"', body, flags=re.A): url = i.group(1) p = urlparse(url).query p = parse_qs(p) diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index f995b53f3..c1d049432 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -68,7 +68,7 @@ def NOTIFY_USERS(text, v): if word in text.lower() and id not in notify_users and v.id != id: notify_users.add(id) soup = BeautifulSoup(text, 'lxml') - for mention in soup.find_all("a", href=re.compile("^\/id\/([0-9]+)")): + for mention in soup.find_all("a", href=re.compile("^\/id\/([0-9]+)", flags=re.A)): id = int(mention["href"].split("/id/")[1]) if id != v.id: user = g.db.query(User).filter_by(id=id).one_or_none() diff --git a/files/helpers/const.py b/files/helpers/const.py index 9d80bec87..8ec161eb1 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -668,5 +668,5 @@ db = db_session() marseys_const = [x[0] for x in db.query(Marsey.name).all()] + ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','exclamationpoint','period','questionmark'] db.close() -if SITE == 'PCM': valid_username_regex = re.compile("^[a-zA-Z0-9_\-А-я]{3,25}$") -else: valid_username_regex = re.compile("^[a-zA-Z0-9_\-]{3,25}$") \ No newline at end of file +if SITE == 'PCM': valid_username_regex = re.compile("^[a-zA-Z0-9_\-А-я]{3,25}$", flags=re.A) +else: valid_username_regex = re.compile("^[a-zA-Z0-9_\-]{3,25}$", flags=re.A) \ No newline at end of file diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index e55026e40..c8c39ffb1 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -125,7 +125,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): sanitized = re.sub('(^|\s|\n|

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

)@((\w|-){1,25})', sanitized, flags=re.A): + for i in re.finditer(valid_username_regex, sanitized, flags=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): @@ -135,7 +135,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): sanitized = sanitized.replace(i.group(0), f'''{i.group(1)}@{u.username}''', 1) - for i in re.finditer('https://i\.imgur\.com/(([^_]*?)\.(jpg|png|jpeg))(?!)', sanitized): + for i in re.finditer('https://i\.imgur\.com/(([^_]*?)\.(jpg|png|jpeg))(?!)', sanitized, flags=re.A): sanitized = sanitized.replace(i.group(1), i.group(2) + "_d.webp?maxwidth=9999&fidelity=high") if noimages: @@ -203,7 +203,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): old = i.group(0) if 'marseylong1' in old or 'marseylong2' in old or 'marseyllama1' in old or 'marseyllama2' in old: new = old.lower().replace(">", " class='mb-0'>") else: new = old.lower() - for i in re.finditer('(?', new, flags=re.I) + new = re.sub(f'(?', new, flags=re.I|re.A) if comment: marseys_used.add(emoji) sanitized = sanitized.replace(old, new) - emojis = list(re.finditer('(? 20: edit = True captured = [] @@ -247,7 +247,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): else: emoji = old if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): - sanitized = re.sub(f'(?', sanitized, flags=re.I) + sanitized = re.sub(f'(?', sanitized, flags=re.I|re.A) if comment: marseys_used.add(emoji) else: classes = 'emoji' @@ -258,14 +258,14 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): else: emoji = old if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): - sanitized = re.sub(f'(?', sanitized, flags=re.I) + sanitized = re.sub(f'(?', sanitized, flags=re.I|re.A) 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://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") if "https://youtube.com/watch?v=" in sanitized: sanitized = sanitized.replace("?t=", "&t=") - for i in re.finditer('" target="_blank">(https://youtube\.com/watch\?v\=(.*?))(?!)', sanitized): + for i in re.finditer('" target="_blank">(https://youtube\.com/watch\?v\=(.*?))(?!)', sanitized, flags=re.A): url = i.group(1) yt_id = i.group(2).split('&')[0].split('%')[0] replacing = f'{url}' @@ -281,17 +281,17 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): sanitized = sanitized.replace(replacing, htmlsource) if not noimages: - for i in re.finditer('>(https://.*?\.(mp4|webm|mov|MP4|WEBM|MOV))

', sanitized): + for i in re.finditer('>(https://.*?\.(mp4|webm|mov|MP4|WEBM|MOV))

', sanitized, flags=re.A): sanitized = sanitized.replace(f'

{i.group(1)}

', f'

') - for i in re.finditer('

(https:.*?\.(mp4|webm|mov|MP4|WEBM|MOV))

', sanitized): + for i in re.finditer('

(https:.*?\.(mp4|webm|mov|MP4|WEBM|MOV))

', sanitized, flags=re.A): sanitized = sanitized.replace(i.group(0), f'

') for rd in ["://reddit.com", "://new.reddit.com", "://www.reddit.com", "://redd.it", "://libredd.it"]: sanitized = sanitized.replace(rd, "://old.reddit.com") sanitized = sanitized.replace("old.reddit.com/gallery", "new.reddit.com/gallery") - sanitized = re.sub(' (https:\/\/[^ <>]*)', r' \1', sanitized) - sanitized = re.sub('

(https:\/\/[^ <>]*)', r'

\1

', sanitized) + sanitized = re.sub(' (https:\/\/[^ <>]*)', r' \1', sanitized, flags=re.A) + sanitized = re.sub('

(https:\/\/[^ <>]*)', r'

\1

', sanitized, flags=re.A) if comment: for marsey in g.db.query(Marsey).filter(Marsey.name.in_(marseys_used)).all(): @@ -315,7 +315,7 @@ def filter_emojis_only(title, edit=False, graceful=False): title = bleach.clean(title, tags=[]) - emojis = list(re.finditer('(? 20: edit = True captured = [] @@ -335,7 +335,7 @@ def filter_emojis_only(title, edit=False, graceful=False): else: emoji = old if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): - title = re.sub(f'(?', title, flags=re.I) + title = re.sub(f'(?', title, flags=re.I|re.A) else: classes = 'emoji' @@ -346,9 +346,9 @@ def filter_emojis_only(title, edit=False, graceful=False): else: emoji = old if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): - title = re.sub(f'(?', title, flags=re.I) + title = re.sub(f'(?', title, flags=re.I|re.A) - title = re.sub('~~(.*?)~~', r'\1', title) + title = re.sub('~~(.*?)~~', r'\1', title, flags=re.A) signal.alarm(0) diff --git a/files/routes/comments.py b/files/routes/comments.py index aaac1df2b..9e596c7b4 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -417,7 +417,7 @@ def api_comment(v): g.db.add(c_choice) if request.host == 'pcmemes.net' and c.body.lower().startswith("based"): - pill = re.match("based and (.{1,20}?)(-| )pilled", body, flags=re.IGNORECASE) + pill = re.match("based and (.{1,20}?)(-| )pilled", body, flags=re.I|re.A) if level == 1: basedguy = get_account(parent_post.author_id) else: basedguy = get_account(c.parent_comment.author_id) diff --git a/files/routes/login.py b/files/routes/login.py index b95298dab..066db2526 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -4,7 +4,7 @@ from files.__main__ import app, limiter from files.helpers.const import * import requests -valid_password_regex = re.compile("^.{8,100}$") +valid_password_regex = re.compile("^.{8,100}$", flags=re.A) @app.get("/login") @auth_desired @@ -270,10 +270,10 @@ def sign_up_post(v): "password") == request.values.get("password_confirm"): return new_signup("Passwords did not match. Please try again.") - if not re.fullmatch(valid_username_regex, username): + if not re.fullmatch(valid_username_regex, username, flags=re.A): return new_signup("Invalid username") - if not re.fullmatch(valid_password_regex, request.values.get("password")): + if not re.fullmatch(valid_password_regex, request.values.get("password"), flags=re.A): return new_signup("Password must be between 8 and 100 characters.") email = request.values.get("email").strip().lower() diff --git a/files/routes/posts.py b/files/routes/posts.py index 83fca0431..a683765d5 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -1339,7 +1339,7 @@ def submit_post(v, sub=None): gevent.spawn(archiveorg, newposturl) url_regex = '(.*?)<\/a>' - for url_match in list(re.finditer(url_regex, post.body_html))[:20]: + for url_match in list(re.finditer(url_regex, post.body_html, flags=re.A))[:20]: href = url_match.group(1) if not href: continue diff --git a/files/routes/settings.py b/files/routes/settings.py index 13aa3a3da..deb131112 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -14,7 +14,7 @@ from files.helpers.discord import add_role from shutil import copyfile import requests -valid_password_regex = re.compile("^.{8,100}$") +valid_password_regex = re.compile("^.{8,100}$", flags=re.A) YOUTUBE_KEY = environ.get("YOUTUBE_KEY", "").strip() GUMROAD_TOKEN = environ.get("GUMROAD_TOKEN", "").strip() @@ -532,7 +532,7 @@ def settings_security_post(v): if request.values.get("new_password") != request.values.get("cnf_password"): return render_template("settings_security.html", v=v, error="Passwords do not match.") - if not re.fullmatch(valid_password_regex, request.values.get("new_password")): + if not re.fullmatch(valid_password_regex, request.values.get("new_password"), flags=re.A): return render_template("settings_security.html", v=v, error="Password must be between 8 and 100 characters.") if not v.verifyPass(request.values.get("old_password")): @@ -859,7 +859,7 @@ def settings_name_change(v): v=v, error="You didn't change anything") - if not re.fullmatch(valid_username_regex, new_name): + if not re.fullmatch(valid_username_regex, new_name, flags=re.A): return render_template("settings_profile.html", v=v, error="This isn't a valid username.") diff --git a/files/routes/subs.py b/files/routes/subs.py index 2789c778e..a2ab8a9ca 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -4,7 +4,7 @@ from files.helpers.wrappers import * from files.classes import * from .front import frontlist -valid_sub_regex = re.compile("^[a-zA-Z0-9_\-]{3,20}$") +valid_sub_regex = re.compile("^[a-zA-Z0-9_\-]{3,20}$", flags=re.A) @@ -273,7 +273,7 @@ def create_sub2(v): if not name: abort(400) name = name.strip().lower() - if not re.fullmatch(valid_sub_regex, name): + if not re.fullmatch(valid_sub_regex, name, flags=re.A): return render_template("sub/create_sub.html", v=v, error="Sub name not allowed."), 400 sub = g.db.query(Sub).filter_by(name=name).one_or_none() diff --git a/files/routes/users.py b/files/routes/users.py index 0a6ecb906..e994e5224 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -493,7 +493,7 @@ def message2(v, username): if 'linkedin.com' in message: return {"error": "This domain 'linkedin.com' is banned."}, 403 - message = re.sub('!\[\]\((.*?)\)', r'\1', message) + message = re.sub('!\[\]\((.*?)\)', r'\1', message, flags=re.A) text_html = sanitize(message, noimages=True) @@ -540,7 +540,7 @@ def messagereply(v): if 'linkedin.com' in message: return {"error": "this domain 'linkedin.com' is banned"} - message = re.sub('!\[\]\((.*?)\)', r'\1', message) + message = re.sub('!\[\]\((.*?)\)', r'\1', message, flags=re.A) id = int(request.values.get("parent_id")) parent = get_comment(id, v=v)