From 0750cd180adc7be0cad69f12b31a3d7709eeb678 Mon Sep 17 00:00:00 2001 From: n9k Date: Mon, 1 Aug 2022 00:37:04 +0000 Subject: [PATCH] Emotes: validate when loading --- anonstream/emote.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/anonstream/emote.py b/anonstream/emote.py index f1c33c7..26bc5dc 100644 --- a/anonstream/emote.py +++ b/anonstream/emote.py @@ -3,12 +3,19 @@ import re from quart import escape -class BadEmoteName(Exception): +class BadEmote(Exception): + pass + +class BadEmoteName(BadEmote): pass def load_emote_schema(filepath): with open(filepath) as fp: emotes = json.load(fp) + for key in ('name', 'file', 'width', 'height'): + for emote in emotes: + if key not in emote: + raise BadEmote(f'emotes must have a `{key}`: {emote}') precompute_emote_regex(emotes) return emotes