diff --git a/CHANGELOG.md b/CHANGELOG.md index 45f6aa0..0165779 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,13 +5,17 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Fixed +- Parsing of title case fields with the *strict_title_case* flag; now, when an error occurs, an `CueValidationError` is thrown instead of an `ValueError`. +- `CHANGELOG.md` markup. + ## [1.0.3] - 2025-12-26 ### Removed - Index parsing stdout warning. ### Changed -- The track field type of TrackData from *int|None* to *int*, and now it is mandatory in the model. +- The track field type of `TrackData` from *int|None* to *int*, and now it is mandatory in the model. ## [1.0.2] - 2025-12-18 @@ -20,7 +24,7 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Seconds property in the FrameTime. ### Fixed -- CHANGELOG versions diff link. +- `CHANGELOG.md` versions diff link. ## [1.0.1] - 2025-11-30 diff --git a/cuetools/parser/handlers.py b/cuetools/parser/handlers.py index b1372d2..8d41750 100644 --- a/cuetools/parser/handlers.py +++ b/cuetools/parser/handlers.py @@ -1,5 +1,5 @@ from typing import Callable -from cuetools.parser.errors import CueParseError +from cuetools.parser.errors import CueParseError, CueValidationError from cuetools.parser.lex import Token, TokenMatch from cuetools.types.title_case import TitleCase @@ -17,7 +17,10 @@ def title_case_handler( match value.type: case Token.ARG_QUOTES | Token.ARG: if strict: - dto_strict_setter(TitleCase(value.lexeme)) + try: + dto_strict_setter(TitleCase(value.lexeme)) + except ValueError as e: + raise CueValidationError(line_idx, line, value.pos, value.lexeme, e) else: dto_setter(value.lexeme) case _: diff --git a/tests/test_parser.py b/tests/test_parser.py index 67a2f5e..19c4a49 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -4,7 +4,7 @@ import logging from cuetools.models import AlbumData, RemData -from cuetools.parser.errors import CueParseError +from cuetools.parser.errors import CueParseError, CueValidationError logger = logging.getLogger(__name__) @@ -81,6 +81,13 @@ def test_line_parsing(): assert cue == AlbumData(title='The Title Of Album', performer='The Performer') + # title_case_handler() should raise CueValidation Error + cue_sheet = """TITLE "The title of album""" '' + + with pytest.raises(CueValidationError) as e: + cue = cuetools.loads(cue_sheet, strict_title_case=True) + logger.debug(str(e.value)) + cue_sheet = """FILE "The Title Of Album:::"!%^&" WAVE""" with pytest.raises(CueParseError) as e: cue = cuetools.loads(cue_sheet)