fix(chess): parse compact PGN move numbers (1.e4) on import - #946
Open
abdulwaarith0 wants to merge 1 commit into
Open
fix(chess): parse compact PGN move numbers (1.e4) on import#946abdulwaarith0 wants to merge 1 commit into
abdulwaarith0 wants to merge 1 commit into
Conversation
parse_moves() stripped move numbers with ^\d+\.+$, which only matches when the number is its own whitespace-separated token (1. e4). Compact PGNs where the number is glued to the move (1.e4 e5 2.Nf3) tokenized to ["1.e4", "2.Nf3", ...], slipped through the filter, and were rejected by the SAN parser — so POST /games/import returned a false 422 "Illegal move" for legal games. Strip a leading move-number prefix from each token (^\d+\.+, no trailing anchor) instead of dropping whole-number-only tokens, handling 1.e4, 1. e4, 1...e5, and 10.Ba2 uniformly. Adds regression tests for compact, black-continuation, and two-digit move numbers. Closes OpenKnight-Foundation#945
abdulwaarith0
force-pushed
the
fix/pgn-compact-move-numbers
branch
from
August 15, 2026 10:42
a678085 to
c869f8e
Compare
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.
Summary
parse_moves()inbackend/modules/chess/src/pgn.rsstripped move numbers with^\d+\.+$, which only matches when the move number is its own whitespace-separated token (the spaced form1. e4). A compact but valid PGN where the number is glued to the move (1.e4 e5 2.Nf3 Nc6, produced by many exporters/engines) tokenized to["1.e4", "e5", "2.Nf3", "Nc6"]; the1.e4/2.Nf3tokens slipped through the filter and were rejected by the SAN parser.This is live via the JWT-authenticated
POST /games/importendpoint (backend/modules/api/src/games.rs:396), so importing a compact-format PGN returned a 422 "Illegal move" for a perfectly legal game.Fix
Strip a leading move-number prefix from each token (
^\d+\.+, no trailing$anchor) instead of dropping whole-number-only tokens:This handles
1.e4,1. e4,1...e5, and10.Ba2uniformly.Before / after
1.e4 e5 2.Nf3 Nc6(compact)["1.e4","e5","2.Nf3","Nc6"]→ 422 ❌["e4","e5","Nf3","Nc6"]→ ✅1. e4 e5 2. Nf3 Nc6(spaced)["e4","e5","Nf3","Nc6"]✅Tests
Added regression tests for compact, black-continuation (
1...e5), and two-digit move numbers. All 9 pgn tests pass (6 existing + 3 new).Closes #945