Fix bug with emojis in the filename (#263)

This commit is contained in:
Serene
2021-04-12 21:11:55 +10:00
committed by Ali Parlakci
parent 5758aad48b
commit 62dedb6c95
2 changed files with 29 additions and 8 deletions

View File

@@ -44,7 +44,7 @@ class FileNameFormatter:
for key in attributes.keys():
if re.search(fr'(?i).*{{{key}}}.*', result):
key_value = str(attributes.get(key, 'unknown'))
key_value = bytes(key_value, 'utf-8').decode('unicode-escape')
key_value = FileNameFormatter._convert_unicode_escapes(key_value)
result = re.sub(fr'(?i){{{key}}}', key_value, result,)
logger.log(9, f'Found key string {key} in name')
@@ -55,6 +55,16 @@ class FileNameFormatter:
return result
@staticmethod
def _convert_unicode_escapes(in_string: str) -> str:
pattern = re.compile(r'(\\u\d{4})')
matches = re.search(pattern, in_string)
if matches:
for match in matches.groups():
converted_match = bytes(match, 'utf-8').decode('unicode-escape')
in_string = in_string.replace(match, converted_match)
return in_string
@staticmethod
def _generate_name_dict_from_submission(submission: Submission) -> dict:
submission_attributes = {