Emotes: allow automatic width/height
このコミットが含まれているのは:
コミット
2820ef9e21
|
@ -23,10 +23,12 @@ def get_scrollback(messages):
|
||||||
@lru_cache
|
@lru_cache
|
||||||
def get_emote_markup(emote_name, emote_file, emote_width, emote_height):
|
def get_emote_markup(emote_name, emote_file, emote_width, emote_height):
|
||||||
emote_name_markup = escape(emote_name)
|
emote_name_markup = escape(emote_name)
|
||||||
|
width = '' if emote_width is None else f'width="{escape(emote_width)}" '
|
||||||
|
height = '' if emote_height is None else f'height="{escape(emote_height)}" '
|
||||||
return Markup(
|
return Markup(
|
||||||
f'''<img class="emote" '''
|
f'''<img class="emote" '''
|
||||||
f'''src="{url_for('static', filename=emote_file)}" '''
|
f'''src="{escape(url_for('static', filename=emote_file))}" ''' # XXX cherry-pick security fix
|
||||||
f'''width="{escape(emote_width)}" height="{escape(emote_height)}" '''
|
f'''{width}{height}'''
|
||||||
f'''alt="{emote_name_markup}" title="{emote_name_markup}">'''
|
f'''alt="{emote_name_markup}" title="{emote_name_markup}">'''
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -35,10 +35,13 @@ def precompute_emote_regex(schema):
|
||||||
for emote in schema:
|
for emote in schema:
|
||||||
assert emote['name'], 'emote names cannot be empty'
|
assert emote['name'], 'emote names cannot be empty'
|
||||||
assert not re.search(r'\s', emote['name']), \
|
assert not re.search(r'\s', emote['name']), \
|
||||||
'whitespace is not allowed in emote names'
|
f'whitespace is not allowed in emote names: {emote["name"]!r}'
|
||||||
|
for length in (emote['width'], emote['height']):
|
||||||
|
assert length is None or isinstance(length, int) and length >= 0, \
|
||||||
|
f'emote dimensions must be null or non-negative integers: {emote["name"]!r}'
|
||||||
# If the emote name begins with a word character [a-zA-Z0-9_],
|
# If the emote name begins with a word character [a-zA-Z0-9_],
|
||||||
# match only if preceded by a non-word character or the empty
|
# match only if preceded by a non-word character or the empty
|
||||||
# string. Similarly for the end of the emote name.
|
# string. Similarly for the end of the emote name.
|
||||||
# Examples:
|
# Examples:
|
||||||
# * ":joy:" matches "abc :joy:~xyz" and "abc:joy:xyz"
|
# * ":joy:" matches "abc :joy:~xyz" and "abc:joy:xyz"
|
||||||
# * "JoySi" matches "abc JoySi~xyz" but NOT "abcJoySiabc"
|
# * "JoySi" matches "abc JoySi~xyz" but NOT "abcJoySiabc"
|
||||||
|
|
読み込み中…
新しいイシューから参照