Skip to content

Commit 5fe326f

Browse files
committed
fix: drop null bytes when parsing string files
1 parent 5eb8423 commit 5fe326f

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

hearthstone/stringsfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def load_json(fp) -> StringsDict:
2525

2626

2727
def load_txt(fp) -> StringsDict:
28+
fp = map(lambda x: x.replace("\0", ""), fp)
2829
reader = csv.DictReader(
2930
filter(lambda row: row.strip() and not row.startswith("#"), fp),
3031
delimiter="\t"

tests/test_stringsfile.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,14 @@ def test_load_blank_line():
2626
"TEXT": "The only escape is death!"
2727
}
2828
}
29+
30+
31+
def test_handle_null_bytes():
32+
NULL_BYTE_STRING = """TAG TEXT COMMENT AUDIOFILE
33+
SOME_STRING_KEY There's a bad null byte at the end!\0""" # noqa: W291
34+
35+
assert load_txt(StringIO(NULL_BYTE_STRING)) == {
36+
"SOME_STRING_KEY": {
37+
"TEXT": "There's a bad null byte at the end!",
38+
}
39+
}

0 commit comments

Comments
 (0)