[Fix] forge yaml_utils self-parser embedded newline escaping#192
Merged
Conversation
yaml_scalar() quoted multi-line values without escaping embedded \n/\r, so the writer emitted raw newlines inside a "quoted" scalar spanning several physical lines. The line-based self-parser then misread each embedded line (e.g. markdown bullets like "- priority: P2") as a new field, fragmenting a single item into many. Escape \n/\r to \\n/\\r on write and restore them on read, keeping every field on one physical line as the self-parser assumes. Fixes #189. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Collapsing "\r\n" to "\\n" before the independent \n/\r replacements discarded the \r, so CRLF values silently became LF on read. Escape \n and \r independently instead so CRLF, lone CR, and LF all restore exactly. Addresses PR #192 review feedback. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
BlueEventHorizon
marked this pull request as ready for review
July 9, 2026 12:40
13 tasks
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.
概要
yaml_utils.py)が、複数行文字列フィールド(Markdown 箇条書きを含むbody/reason等)を含む plan/findings_state.yaml で item を誤って断片化するバグを修正(Fixes [Bug] yaml_utils.py の自家製YAMLパーサーが、bodyフィールドの複数行文字列を誤って断片分解する #189)背景
Issue #189:
/forge:reviewの評価結果統合時、finding の body に複数行 Markdown 箇条書きが含まれると、本来 5 件のはずの finding が 19 件に断片化される不具合が報告された。原因は reader ではなく writer 側にあった。
yaml_scalar()がダブルクォート文字列内の実改行をエスケープしていなかったため、複数行テキストを書き出すと「クォートされた値が複数物理行に割れる」という、自家製パーサーの前提(1 フィールド = 1 物理行)を破る不正な YAML が生成されていた。読み込み側の行ベース parser はこの前提に従うため、埋め込まれた- priority: P2のような行を新しいフィールド開始と誤認していた。Issue 本文が提案していた「PyYAML 導入」は採用していない。本リポジトリの
plugins/配下スクリプトは外部依存ゼロ・標準ライブラリのみで動作する方針(配布物としてpython3 script.pyを直接実行するため、インストールステップを前提にできない)であり、今回は自家製パーサー側の root cause 修正で解決した。やったこと
yaml_utils.pyのyaml_scalar(): 文字列に\n/\rが含まれる場合\\n/\\rにエスケープし、常に単一物理行に収めるyaml_utils.pyの_unescape_double_quoted(): 読み込み時に\\n/\\rを実際の改行文字へ復元する\nと実改行エスケープの混同がないことの確認)やらないこと(このプルリクエストのスコープ外とすること)
.claude/.temp/は完了セッションで消える ephemeral ディレクトリのため対象外)レビュー観点
yaml_scalar()のエスケープ順序(バックスラッシュ → 改行)が、ユーザーデータ中のリテラル\n(バックスラッシュ+n の2文字)と実改行のエスケープを混同しないことをテストで確認済みレビューレベル
Lv0: まったく見ないでAcceptするLv1: ぱっとみて違和感がないかチェックしてAcceptするLv3: 実際に環境で動作確認したうえでAcceptする備考
Issue #189 にも同内容の技術的検討をコメント済み。