Skip to content

fix(chess): strip nested PGN variations on import - #1177

Merged
chinweobtagaz merged 1 commit into
OpenKnight-Foundation:mainfrom
abdulwaarith0:fix/pgn-nested-variations
Sep 2, 2026
Merged

fix(chess): strip nested PGN variations on import#1177
chinweobtagaz merged 1 commit into
OpenKnight-Foundation:mainfrom
abdulwaarith0:fix/pgn-nested-variations

Conversation

@abdulwaarith0

Copy link
Copy Markdown
Contributor

parse_moves stripped variations with a single \([^()]*\) regex pass, which only matches the innermost parentheses. On nested variations like (1. d4 (2. c4) Nf6) it removed the inner (2. c4) and left the outer parens and their moves behind, so those tokens reached SAN validation and failed the import with a 422.

This walks the movetext tracking parenthesis depth instead, so every nesting level is removed in one pass, and it tolerates unbalanced parens without panicking.

Added a parse test with a nested variation (which errored before) plus a unit test for the helper.

Closes #1176.

@chinweobtagaz
chinweobtagaz merged commit 3ac840f into OpenKnight-Foundation:main Sep 2, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PGN import fails on nested variations

2 participants