fix(parser): [[include]] 末尾の余分な ] を value 側に吸収 (greedy close)#49
Merged
Conversation
3.1.1 で「最後の引数値が ] で終わる multi-line include の終端を見つける」 修正を入れたが、close を「最初の ]]」で行う実装になっており、残りの `]` が include の外に raw text として漏れ出ていた。 Wikidot 本家は greedy に「最後の ]] で close、間の ] は最終 attribute value に 吸収」を行う ([[include foo|key=val|bar=--]|]] の改行省略形 [[include foo|key=val|bar=--]]] で bar=--] となる)。これを再現するため、 ]] で depth=0 になった時点で直後の ] を while ループで読み飛ばし、close 位置を 最後の ]] の終わりに合わせるよう変更。 副次的に 3.1.1 で導入した isRestOfLineBlank の ] 許容は不要になるため revert。
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
wdpr-demo-v1 | 786eab5 | Commit Preview URL Branch Preview URL |
Jun 10 2026, 03:30 AM |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
decompiler-preview | 786eab5 | Commit Preview URL Branch Preview URL |
Jun 10 2026, 03:30 AM |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
wdpr-demo-v1-files | 786eab5 | Commit Preview URL Branch Preview URL |
Jun 10 2026, 03:30 AM |
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.
背景
3.1.1 の
isRestOfLineBlankの]許容修正で multi-line include 自体は close できるようになったが、close を「最初の]]」で行う実装になっており、[[include foo\n|key=val|bar=--]]]のようなケースでbar=--、残り]が include の外に paragraph として漏れ出ていた。実環境ではテンプレ側で次のような Wikidot コメント wrap idiom を使っており、
{$a}に--]を代入することで[!-- --]で comment を早期に閉じ、本来表出すべきコンテンツを出す:3.1.1 だと残り
]が<p>]</p>として並ぶだけでなく、--]ではなく--で value が切れていたためテンプレ側の{$a} = --]イディオムが成立しない。変更点
scanIncludeDirectivesで]]を見つけて depth=0 になった時、directive に attribute セクションがある場合のみ 直後の]を while ループで吸収して close を]]]+の末尾に合わせる。属性ありの判定:
|を含む ([[include foo |k=v]])、または[[include foo k=v]])=単独での判定は不可。page name に=が含まれる場合 ([[include foo=bar]]) を誤検出するため。副次的に 3.1.1 で導入した
isRestOfLineBlankの]許容は不要になるので revert。挙動の差分
[[include tmpl|cap= --]]]<<-->>]<<--]>>[[include tmpl|cap= x]]]]]<<x>>]]]<<x]]]>>[[include tmpl]]]]]](変化なし)[[include foo=bar]]]]]](page name の=を誤検出しない)[[include foo bar=--]]]]]--]、残り 0Test plan
bun run lint(10 warnings, 0 errors — 既存箇所のみ)bun run formatbun run typecheckbun test(1302 pass / 0 fail)tests/unit/module/include/resolve.test.ts):]]直後の]を value に吸収 (multi-line)]]を吸収しないこと=を含むケース / space-separated parametertests/unit/parser/resolve/include-comment-integration.test.ts):a=--]]]で comment 早閉じ → 中身表出a未指定で comment swallowing → 中身非表示--]のバリエーション