Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat UTF-16 strings in binary VDF as little-endian #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Treat UTF-16 strings in binary VDF as little-endian
Integers in binary VDF are already treated as little-endian (least
significant byte first) regardless of CPU architecture, but the 16-bit
units in UTF-16 didn't get the same treatment. This led to a test failure
on big-endian machines.

Resolves: #33
Signed-off-by: Simon McVittie <[email protected]>
  • Loading branch information
smcv committed Dec 15, 2023
commit fe85ab850bc0f5abe6bc788e167c75d6d09d981b
4 changes: 2 additions & 2 deletions vdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def read_string(fp, wide=False):
result = buf[:end]

if wide:
result = result.decode('utf-16')
result = result.decode('utf-16le')
elif bytes is not str:
result = result.decode('utf-8', 'replace')
else:
Expand Down Expand Up @@ -469,7 +469,7 @@ def _binary_dump_gen(obj, level=0, alt_format=False):
value = value.encode('utf-8') + BIN_NONE
yield BIN_STRING
except:
value = value.encode('utf-16') + BIN_NONE*2
value = value.encode('utf-16le') + BIN_NONE*2
yield BIN_WIDESTRING
yield key + BIN_NONE + value
elif isinstance(value, float):
Expand Down
Loading