Repository navigation
reject en-passant tokens the parser cannot map - #95
Merged
Merged
Conversation
`[3|6]` is a character class of `3`, `|` and `6`, so every `<file>|`
spelling (`a|`, `e|`, ...) passes `validateFen()` with "No errors".
`Chess::load()` then maps the token through `Board::SQUARES[$token]`,
misses, and only emits an `E_WARNING` ("Undefined array key"), leaving
`epSquare` null and `fen()` printing `-`.
Reject the pipe at the gate instead: `[36]` is the intended set, and no
valid en-passant square contains `|`.
Covered by a new FenTest data row, which fails on master
(`Failed asserting that 0 matches expected 4`).
garak
approved these changes
Oct 21, 2026
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.
What
validateFen()'s ep criterion is/^(-|[a-h][3|6])$/. Inside a character class|is a literal, so the criterion is "-, or a file +3/|/6" —a|,e|,h|, … all pass with code0("No errors").Chess::load()then readsBoard::SQUARES[$tokens[3]].a|is an undefined key: PHP 8 raises anE_WARNING("Undefined array key"),$epSquarestays null, andfen()prints-:So the validator accepts a string the parser cannot represent. Whether that surfaces as an error depends entirely on the caller: with Laravel's
HandleExceptions(or any handler that throws on warnings) the warning throws; witherror_reporting(0),@, or a plain script the same FEN loads and is keyed/echoed verbatim. In chessable-b1 that produced a 422 that rested on the framework error handler rather than on the FEN itself, plus a cache key no valid spelling can produce.Change
[36]is the intended set; no valid ep square contains|. This only moves<file>|tokens from accepted to error code4— every currently valid FEN keeps its verdict.Test
New
FenTestrow,['8/8/8/8/8/8/8/8 b - a| 0 1', 4]. It fails on master (Failed asserting that 0 matches expected 4) and passes with the fix.Full suite: 282 tests, 1 skipped (existing slow perft). php-cs-fixer and PHPStan level 8 clean.