master
Aevann1 2022-02-26 20:53:17 +02:00
parent b1feaf9c30
commit e0dfe332c2
10 changed files with 33 additions and 33 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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}$")
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)

View File

@ -125,7 +125,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False):
sanitized = re.sub('(^|\s|\n|<p>)\/?(s\/(\w|-){3,25})', r'\1<a href="/\2" rel="nofollow noopener noreferrer">/\2</a>', sanitized, flags=re.A)
for i in re.finditer('(^|\s|\n|<p>)@((\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)}<a href="/id/{u.id}"><img loading="lazy" src="/uid/{u.id}/pic" class="pp20">@{u.username}</a>''', 1)
for i in re.finditer('https://i\.imgur\.com/(([^_]*?)\.(jpg|png|jpeg))(?!</code>)', sanitized):
for i in re.finditer('https://i\.imgur\.com/(([^_]*?)\.(jpg|png|jpeg))(?!</code>)', 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('(?<!"):([!#A-Za-z0-9]{1,30}?):', new):
for i in re.finditer('(?<!"):([!#A-Za-z0-9]{1,30}?):', new, flags=re.A):
emoji = i.group(1).lower()
if emoji.startswith("#!") or emoji.startswith("!#"):
classes = 'emoji-lg mirrored'
@ -223,12 +223,12 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False):
if remoji == 'marseyrandom': remoji = choice(marseys_const)
if path.isfile(f'files/assets/images/emojis/{remoji}.webp'):
new = re.sub(f'(?<!"):{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{emoji}:" title=":{emoji}:" class="{classes}" src="/e/{remoji}.webp" >', new, flags=re.I)
new = re.sub(f'(?<!"):{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{emoji}:" title=":{emoji}:" class="{classes}" src="/e/{remoji}.webp" >', new, flags=re.I|re.A)
if comment: marseys_used.add(emoji)
sanitized = sanitized.replace(old, new)
emojis = list(re.finditer('(?<!#"):([!#A-Za-z0-9]{1,30}?):', sanitized))
emojis = list(re.finditer('(?<!#"):([!#A-Za-z0-9]{1,30}?):', sanitized, flags=re.A))
if len(emojis) > 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'(?<!"):{i.group(1).lower()}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":!{old}:" title=":!{old}:" class="{classes}" src="/e/{emoji}.webp">', sanitized, flags=re.I)
sanitized = re.sub(f'(?<!"):{i.group(1).lower()}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":!{old}:" title=":!{old}:" class="{classes}" src="/e/{emoji}.webp">', 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'(?<!"):{i.group(1).lower()}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{old}:" title=":{old}:" class="{classes}" src="/e/{emoji}.webp">', sanitized, flags=re.I)
sanitized = re.sub(f'(?<!"):{i.group(1).lower()}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{old}:" title=":{old}:" class="{classes}" src="/e/{emoji}.webp">', 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\=(.*?))</a>(?!</code>)', sanitized):
for i in re.finditer('" target="_blank">(https://youtube\.com/watch\?v\=(.*?))</a>(?!</code>)', sanitized, flags=re.A):
url = i.group(1)
yt_id = i.group(2).split('&')[0].split('%')[0]
replacing = f'<a href="{url}" rel="nofollow noopener noreferrer" target="_blank">{url}</a>'
@ -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))</a></p>', sanitized):
for i in re.finditer('>(https://.*?\.(mp4|webm|mov|MP4|WEBM|MOV))</a></p>', sanitized, flags=re.A):
sanitized = sanitized.replace(f'<p><a href="{i.group(1)}" rel="nofollow noopener noreferrer" target="_blank">{i.group(1)}</a></p>', f'<p><video controls preload="none" class="embedvid"><source src="{i.group(1)}" type="video/mp4"></video>')
for i in re.finditer('<p>(https:.*?\.(mp4|webm|mov|MP4|WEBM|MOV))</p>', sanitized):
for i in re.finditer('<p>(https:.*?\.(mp4|webm|mov|MP4|WEBM|MOV))</p>', sanitized, flags=re.A):
sanitized = sanitized.replace(i.group(0), f'<p><video controls preload="none" class="embedvid"><source src="{i.group(1)}" type="video/mp4"></video>')
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' <a target="_blank" rel="nofollow noopener noreferrer" href="\1">\1</a>', sanitized)
sanitized = re.sub('<p>(https:\/\/[^ <>]*)', r'<p><a target="_blank" rel="nofollow noopener noreferrer" href="\1">\1</a></p>', sanitized)
sanitized = re.sub(' (https:\/\/[^ <>]*)', r' <a target="_blank" rel="nofollow noopener noreferrer" href="\1">\1</a>', sanitized, flags=re.A)
sanitized = re.sub('<p>(https:\/\/[^ <>]*)', r'<p><a target="_blank" rel="nofollow noopener noreferrer" href="\1">\1</a></p>', 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('(?<!"):([!A-Za-z0-9]{1,30}?):', title))
emojis = list(re.finditer('(?<!"):([!A-Za-z0-9]{1,30}?):', title, flags=re.A))
if len(emojis) > 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'(?<!"):!{old}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":!{old}:" title=":!{old}:" src="/e/{emoji}.webp" class="{classes}">', title, flags=re.I)
title = re.sub(f'(?<!"):!{old}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":!{old}:" title=":!{old}:" src="/e/{emoji}.webp" class="{classes}">', 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'(?<!"):{old}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{old}:" title=":{old}:" class="{classes}" src="/e/{emoji}.webp">', title, flags=re.I)
title = re.sub(f'(?<!"):{old}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{old}:" title=":{old}:" class="{classes}" src="/e/{emoji}.webp">', title, flags=re.I|re.A)
title = re.sub('~~(.*?)~~', r'<del>\1</del>', title)
title = re.sub('~~(.*?)~~', r'<del>\1</del>', title, flags=re.A)
signal.alarm(0)

View File

@ -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)

View File

@ -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()

View File

@ -1339,7 +1339,7 @@ def submit_post(v, sub=None):
gevent.spawn(archiveorg, newposturl)
url_regex = '<a href=\"(https?:\/\/[a-z]{1,20}\.[^\"]+)\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">(.*?)<\/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

View File

@ -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.")

View File

@ -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()

View File

@ -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)