Skip to content

Commit

Permalink
ensure fields normalized before checksumming
Browse files Browse the repository at this point in the history
  • Loading branch information
dae committed Mar 13, 2021
1 parent bd95973 commit 1ab085d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pylib/anki/utils.py
Expand Up @@ -15,6 +15,7 @@
import tempfile
import time
import traceback
import unicodedata
from contextlib import contextmanager
from hashlib import sha1
from html.entities import name2codepoint
Expand Down Expand Up @@ -201,8 +202,11 @@ def checksum(data: Union[bytes, str]) -> str:


def fieldChecksum(data: str) -> int:
without_html = stripHTMLMedia(data)
normalized = unicodedata.normalize("NFC", without_html)
utf8_text = normalized.encode("utf-8")
# 32 bit unsigned number from first 8 digits of sha1 hash
return int(checksum(stripHTMLMedia(data).encode("utf-8"))[:8], 16)
return int(checksum(utf8_text)[:8], 16)


# Temp files
Expand Down

0 comments on commit 1ab085d

Please sign in to comment.