refactor: reuse code from remove_surrogates

This commit is contained in:
Thomas Waldmann 2023-01-19 20:58:58 +01:00
parent b3da7d0e72
commit 249189e04e
No known key found for this signature in database
GPG Key ID: 243ACFA951F78E01
1 changed files with 1 additions and 2 deletions

View File

@ -75,8 +75,7 @@ def text_to_json(key, value):
value.encode(coding, errors="strict") # check if pure unicode
except UnicodeEncodeError:
# value has surrogate escape sequences
value_replace_encoded = value.encode(coding, errors="replace")
data[key] = value_replace_encoded.decode(coding, errors="strict")
data[key] = remove_surrogates(value)
value_bytes = value.encode(coding, errors="surrogateescape")
data.update(binary_to_json(key, value_bytes))
else: