瀏覽代碼

refactor: reuse code from remove_surrogates

Thomas Waldmann 2 年之前
父節點
當前提交
249189e04e
共有 1 個文件被更改,包括 1 次插入2 次删除
  1. 1 2
      src/borg/helpers/parseformat.py

+ 1 - 2
src/borg/helpers/parseformat.py

@@ -75,8 +75,7 @@ def text_to_json(key, value):
         value.encode(coding, errors="strict")  # check if pure unicode
         value.encode(coding, errors="strict")  # check if pure unicode
     except UnicodeEncodeError:
     except UnicodeEncodeError:
         # value has surrogate escape sequences
         # 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")
         value_bytes = value.encode(coding, errors="surrogateescape")
         data.update(binary_to_json(key, value_bytes))
         data.update(binary_to_json(key, value_bytes))
     else:
     else: