forked from rDrama/rDrama
linkify reports, flairs, and group descriptions
parent
5b304cbbed
commit
4e449851e2
|
@ -619,7 +619,7 @@ def allowed_attributes_emojis(tag, name, value):
|
|||
|
||||
|
||||
@with_sigalrm_timeout(2)
|
||||
def filter_emojis_only(title, golden=True, count_emojis=False, obj=None, author=None):
|
||||
def filter_emojis_only(title, golden=True, count_emojis=False, obj=None, author=None, link=False):
|
||||
|
||||
title = title.replace("\n", "").replace("\r", "").replace("\t", "").replace('<','<').replace('>','>')
|
||||
|
||||
|
@ -651,12 +651,29 @@ def filter_emojis_only(title, golden=True, count_emojis=False, obj=None, author=
|
|||
|
||||
title = strikethrough_regex.sub(r'\1<del>\2</del>', title)
|
||||
|
||||
title = bleach.clean(
|
||||
title,
|
||||
if link:
|
||||
title = bleach.Cleaner(
|
||||
tags=['img','del','span'],
|
||||
attributes=allowed_attributes_emojis,
|
||||
protocols=['http','https']
|
||||
).replace('\n','')
|
||||
protocols=['http','https'],
|
||||
filters=[
|
||||
partial(
|
||||
LinkifyFilter,
|
||||
skip_tags=["pre"],
|
||||
parse_email=False,
|
||||
url_re=sanitize_url_regex
|
||||
)
|
||||
]
|
||||
).clean(title)
|
||||
else:
|
||||
title = bleach.clean(
|
||||
title,
|
||||
tags=['img','del','span'],
|
||||
attributes=allowed_attributes_emojis,
|
||||
protocols=['http','https']
|
||||
)
|
||||
|
||||
title = title.replace('\n','')
|
||||
|
||||
if len(title) > POST_TITLE_HTML_LENGTH_LIMIT:
|
||||
abort(400, "Rendered title is too long!")
|
||||
|
|
|
@ -945,7 +945,7 @@ def admin_change_flair(user_id, v):
|
|||
abort(400, "New flair is too long (max 256 characters)")
|
||||
|
||||
user.flair = new_flair
|
||||
new_flair = filter_emojis_only(new_flair)
|
||||
new_flair = filter_emojis_only(new_flair, link=True)
|
||||
new_flair = censor_slurs_profanities(new_flair, None)
|
||||
|
||||
user = get_account(user.id)
|
||||
|
|
|
@ -412,7 +412,7 @@ def award_thing(v, thing_type, id):
|
|||
author.flairchanged += 86400
|
||||
else:
|
||||
author.flair = new_flair
|
||||
new_flair = filter_emojis_only(new_flair)
|
||||
new_flair = filter_emojis_only(new_flair, link=True)
|
||||
new_flair = censor_slurs_profanities(new_flair, None)
|
||||
if len(new_flair) > 1000: abort(403)
|
||||
author.flair_html = new_flair
|
||||
|
|
|
@ -356,7 +356,7 @@ def group_change_description(v, group_name):
|
|||
if len(description) > 100:
|
||||
abort(400, "New description is too long (max 100 characters)")
|
||||
|
||||
description_html = filter_emojis_only(description)
|
||||
description_html = filter_emojis_only(description, link=True)
|
||||
if len(description_html) > 1000:
|
||||
abort(400, "Rendered description is too long!")
|
||||
else:
|
||||
|
|
|
@ -27,7 +27,7 @@ def report_post(pid, v):
|
|||
abort(400, "Report reason is too long (max 100 characters)")
|
||||
|
||||
og_flair = reason[1:]
|
||||
reason_html = filter_emojis_only(reason)
|
||||
reason_html = filter_emojis_only(reason, link=True)
|
||||
if len(reason_html) > 350:
|
||||
abort(400, "Rendered report reason is too long!")
|
||||
|
||||
|
@ -95,7 +95,7 @@ def report_comment(cid, v):
|
|||
if len(reason) > 100:
|
||||
abort(400, "Report reason is too long (max 100 characters)")
|
||||
|
||||
reason_html = filter_emojis_only(reason)
|
||||
reason_html = filter_emojis_only(reason, link=True)
|
||||
if len(reason_html) > 350:
|
||||
abort(400, "Rendered report reason is too long!")
|
||||
|
||||
|
|
|
@ -957,7 +957,7 @@ def settings_change_flair(v):
|
|||
flair = process_settings_plaintext("flair", v.flair, 100, None)
|
||||
|
||||
if flair:
|
||||
flair_html = filter_emojis_only(flair)
|
||||
flair_html = filter_emojis_only(flair, link=True)
|
||||
flair_html = censor_slurs_profanities(flair_html, None)
|
||||
|
||||
if len(flair_html) > 1000:
|
||||
|
|
Loading…
Reference in New Issue