Repository navigation
Conversation
Headers.__setitem__ validated custom tags before checking for CR/LF, so the Seven Tag Roster accepted values containing line breaks and StringExporter emitted unreadable PGN. Validate the value for every tag before storing it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Headers.__setitem__rejects\nand\rfor custom tags, but stores the Seven Tag Roster before that check:So this is accepted:
and
str(game)/StringExporterwrites a raw line break inside the quoted header value.chess.pgn.read_headers()then returnsNonefor the exported text. The same assignment to a custom tag (Annotator) correctly raisesValueError.The PGN standard, Section 7 (Tokens), is explicit:
Tag values are string tokens (Section 8.1), so the restriction applies to both roster and custom headers.
Reproduction
Fix
Validate the value after key validation and before the roster/custom dispatch:
This preserves the existing error precedence for invalid custom tag names and does not change any valid header value.
Tests
Added
PgnTestCase.test_headers_reject_line_breaks:Results on
393bdb3:Annotatoralready passes.python3 -m unittest test.PgnTestCase→Ran 69 tests ... OK.python3 -m unittest discover -p 'test*.py'→Ran 352 tests ... OK (skipped=22).Notes