forked from MarseyWorld/MarseyWorld
Fix @mention replacement.
Comments of the style e.g. "@TLSM / @TLSM2" would mistakenly be `sanitize`d to have identical links only on "@TLSM", the latter instance having a dangling 2 on the end. It seems this is purely an issue with text formatting; alerts.py @ NOTIF_USERS had no such issues. The root cause appears to be partly an optimization and partly the use of str.replace without a count limit.master
parent
75d4f0d3aa
commit
76fd1342f3
|
@ -173,15 +173,11 @@ def sanitize(sanitized, alert=False, comment=False, edit=False):
|
|||
|
||||
sanitized = sub_regex.sub(r'\1<a href="/\2">/\2</a>', sanitized)
|
||||
|
||||
captured = []
|
||||
for i in mention_regex.finditer(sanitized):
|
||||
if i.group(0) in captured: continue
|
||||
captured.append(i.group(0))
|
||||
|
||||
u = get_user(i.group(2), graceful=True)
|
||||
|
||||
if u and (not (g.v and g.v.any_block_exists(u)) or g.v.admin_level > 1):
|
||||
sanitized = sanitized.replace(i.group(0), f'''{i.group(1)}<a href="/id/{u.id}"><img loading="lazy" src="/pp/{u.id}">@{u.username}</a>''')
|
||||
sanitized = sanitized.replace(i.group(0), f'''{i.group(1)}<a href="/id/{u.id}"><img loading="lazy" src="/pp/{u.id}">@{u.username}</a>''', 1)
|
||||
|
||||
|
||||
sanitized = imgur_regex.sub(r'\1_d.webp?maxwidth=9999&fidelity=high', sanitized)
|
||||
|
|
Loading…
Reference in New Issue