From e5193cbd464a3c0fe220f83cc1c61f6070ff51ab Mon Sep 17 00:00:00 2001 From: TLSM Date: Sat, 18 Jun 2022 21:22:04 -0400 Subject: [PATCH] Fix mention sanitize when `g.v` not present. This bug was discovered when lottery.check_if_end_lottery_task was failing due to a stack trace thru end_lottery session < badge_grant < send_repeatable_notifications < sanitize L208. In particular, when `flask cron` (helpers/cron.py) executes, it does not set g.v, whereas this code previously assumed that g.v : (None + User) and did not check for its presence. --- files/helpers/sanitize.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 10c098d2e..a6dfdfb47 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -201,11 +201,12 @@ def sanitize(sanitized, alert=False, edit=False): names = set( m.group(2) for m in matches ) users = get_users(names,graceful=True) + v = getattr(g, 'v', None) for u in users: if not u: continue m = [ m for m in matches if u.username.lower() == m.group(2).lower() or u.original_username.lower() == m.group(2).lower() ] for i in m: - if not (g.v and g.v.any_block_exists(u)) or g.v.admin_level > 1: + if not (v and v.any_block_exists(u)) or (v and v.admin_level >= 2): sanitized = sanitized.replace(i.group(0), f'''{i.group(1)}@{u.username}''', 1)