diff --git a/CHANGELOG.md b/CHANGELOG.md index f79f2f5..3120b20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ Format based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). For version numbers I try to follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## v2.1.1 +### Fixed +- Attempting to guess the file format of a non UTF-16 file would crash the + yubiosi 2.0 format guesser, not anymore. + ## v2.1.0 ### Added - [yubiosi] 🎉 initial yubiosi support ! diff --git a/jubeatools/formats/guess.py b/jubeatools/formats/guess.py index dffa041..9b1e3bc 100644 --- a/jubeatools/formats/guess.py +++ b/jubeatools/formats/guess.py @@ -13,7 +13,7 @@ def guess_format(path: Path) -> Format: format is unknown""" if path.is_dir(): raise ValueError("Can't guess chart format for a folder") - + contents = path.read_bytes() return guess_file_format(contents) @@ -238,4 +238,4 @@ def line_has_yubiosi_tag(line: str) -> bool: def looks_like_yubiosi_2_0(contents: bytes) -> bool: text = contents.decode("utf-16") lines = text.splitlines() - return lines and lines[0] == "//Yubiosi 2.0" + return len(lines) >= 1 and lines[0] == "//Yubiosi 2.0" diff --git a/jubeatools/formats/tests/test_guess.py b/jubeatools/formats/tests/test_guess.py index 139393a..b1dbcbd 100644 --- a/jubeatools/formats/tests/test_guess.py +++ b/jubeatools/formats/tests/test_guess.py @@ -1,13 +1,13 @@ -from pathlib import Path - import hypothesis.strategies as st -from hypothesis import given, settings +from hypothesis import given from .. import guess @given(st.binary()) -def test_that_guess_format_only_raises_the_specific_value_error(contents: bytes): +def test_that_guess_format_only_raises_the_specific_value_error( + contents: bytes, +) -> None: try: guess.guess_file_format(contents) except ValueError as e: @@ -15,7 +15,7 @@ def test_that_guess_format_only_raises_the_specific_value_error(contents: bytes) raise -def test_that_yubiosi_2_0_detection_does_not_raise_exception_for_non_utf16_files(): +def test_that_yubiosi_2_0_detection_does_not_raise_exception_for_non_utf16_files() -> None: text = "blablabla" bytes_ = text.encode("ascii") - guess.looks_like_yubiosi_2_0(bytes_) \ No newline at end of file + guess.looks_like_yubiosi_2_0(bytes_)