Skip to content

Commit

Permalink
fix: encode non-ASCII characters in dictionary names
Browse files Browse the repository at this point in the history
  • Loading branch information
Crissium committed Aug 16, 2024
1 parent 42a6d93 commit 9be52a2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server/app/dictionaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ def __init__(self, app: Flask) -> None:
def add_dictionary(self, dictionary_info: dict) -> None:
dictionary_info['dictionary_name'] =\
self._re_illegal_css_selector_chars.sub('', dictionary_info['dictionary_name'])

# Replace characters that fall beyond the ASCII range with e.g. uXXXX
dictionary_info['dictionary_name'] = dictionary_info['dictionary_name'].encode(
'ascii',
'backslashreplace'
).decode('ascii').replace('\\', '')

# Remove whitespace and prepend '__' to make it a valid CSS selector
dictionary_info['dictionary_name'] = '__' + ''.join(dictionary_info['dictionary_name'].split())

Expand Down

0 comments on commit 9be52a2

Please sign in to comment.