diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 071786f214..18d577b5cb 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -99,7 +99,7 @@ allowed_protocols = ['http', 'https'] allowed_styles = ['color', 'background-color', 'font-weight', 'transform', '-webkit-transform'] -def sanitize(sanitized, noimages=False, alert=False): +def sanitize(sanitized, noimages=False, alert=False, comment=False): sanitized = markdown(sanitized) @@ -186,10 +186,10 @@ def sanitize(sanitized, noimages=False, alert=False): sanitized = re.sub('\|\|(.*?)\|\|', r'\1', sanitized) - with open("marsey_count.json", 'r') as f: - marsey_count = loads(f.read()) + if comment: + with open("marsey_count.json", 'r') as f: marsey_count = loads(f.read()) + marseys_used = set() - marseys_used = set() for i in re.finditer("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", sanitized): 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'>") @@ -211,7 +211,7 @@ def sanitize(sanitized, noimages=False, alert=False): if path.isfile(f'files/assets/images/emojis/{remoji}.webp'): new = re.sub(f'(?', new, flags=re.I) - marseys_used.add(emoji) + if comment: marseys_used.add(emoji) sanitized = sanitized.replace(old, new) @@ -222,11 +222,11 @@ def sanitize(sanitized, noimages=False, alert=False): emoji = emoji[1:] if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): sanitized = re.sub(f'(?', sanitized, flags=re.I) - marseys_used.add(emoji) + if comment: marseys_used.add(emoji) elif path.isfile(f'files/assets/images/emojis/{emoji}.webp'): sanitized = re.sub(f'(?', sanitized, flags=re.I) - marseys_used.add(emoji) + if comment: marseys_used.add(emoji) sanitized = sanitized.replace("https://www.", "https://").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") @@ -258,10 +258,10 @@ def sanitize(sanitized, noimages=False, alert=False): sanitized = re.sub(' (https:\/\/[^ <>]*)', r' \1', sanitized) sanitized = re.sub('
(https:\/\/[^ <>]*)', r'
', sanitized) - for emoji in marseys_used: - if emoji in marsey_count: marsey_count[emoji] += 1 - - with open('marsey_count.json', 'w') as f: dump(marsey_count, f) + if comment: + for emoji in marseys_used: + if emoji in marsey_count: marsey_count[emoji] += 1 + with open('marsey_count.json', 'w') as f: dump(marsey_count, f) return sanitized diff --git a/files/routes/comments.py b/files/routes/comments.py index 1e002b96cf..814bb43749 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -211,7 +211,7 @@ def api_comment(v): if v.agendaposter and not v.marseyawarded: body = torture_ap(body, v.username) - body_html = sanitize(body) + body_html = sanitize(body, comment=True) if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html))): return {"error":"You can only type marseys!"}, 403