Skip to content

fix(parser): includeパラメータ値内の]]/triple-linkでdirectiveが途切れる問題を修正#43

Merged
r74tech merged 2 commits into
developfrom
fix/include-nested-bracket-balance
Jun 4, 2026
Merged

fix(parser): includeパラメータ値内の]]/triple-linkでdirectiveが途切れる問題を修正#43
r74tech merged 2 commits into
developfrom
fix/include-nested-bracket-balance

Conversation

@r74tech

@r74tech r74tech commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • include directive のパラメータ値に [[span]]...[[/span]] のような nested [[...]] や単独の ]] が含まれると、従来の正規表現 (INCLUDE_PATTERN) が 最初の ]] で directive を切ってしまい、値が途中で途切れ、残りが外側の wikitext に漏れ出していた問題を修正。
  • 加えて、parameter 値内の triple-bracket link ([[[link]]]) が directive close ]] と同一行で隣接する形 (...|cap=[[[link]]]]]) で link の ]]] と close の ]] のブラケットが重なり再構成できなかった既知のエッジも同時に解消。

Changes

1. ]] での途切れを解消 (59fb1c4)

  • packages/parser/src/parser/rules/block/module/include/resolve.ts:
    • INCLUDE_PATTERN (regex) を廃止し scanIncludeDirectives (bracket-balanced スキャナ) に置換。
    • [[depth+1]]depth-1depth <= 0]] で close。
    • ただし close と認めるのは「opener と同一行」または「行末 (後続が空白のみ)」の ]] のみ。継続行の mid-line ]] (bare / nested) では閉じないため caption 等が途切れない。
    • 同一行条件により inline-trailing ([[include x]] text) は opener 行で閉じ、後続の別 include を巻き込まない。
    • close が見つからない opener は未展開のまま据え置き。
    • expandIterative / expandIterativeAsync をスキャナベースに書き換え。
    • 追加テスト: nested markup / bare ]] / single-line / inline-trailing + 後続 include / triple-link(分離行) / 未バランス opener。

2. triple-bracket link が close で途切れる問題を解消 (277ac35)

  • scanIncludeDirectives[[[ ... ]]] を block の [[/]] とは別の link depth で数える方式に変更。
  • link depth が正のあいだは内部の [[/]] を literal 扱いし block depth を動かさない。link の ]]] が directive close ]] と同一行で隣接 (...|cap=[[[link]]]]]) しても link が途切れず再構成される。
  • directive close 判定は従来どおり block depth の opener-行 / 行末ルールのみに依存。隣接する別 directive を巻き込まない。

Test plan

  • caption 内に [[span class="ruby"]]黄山[[span class="rt"]]きやま[[/span]][[/span]] のようなネストした [[...]] を含む include で、すべての要素が値として保持される。
  • 値内の単独 ]] (例 caption=記号 ]] を含む説明) で directive が早期終了しない。
  • 単一行 ([[include tmpl |cap=[[span]]hi[[/span]]]]) で末尾の ]] で close。
  • inline-trailing ([[include tmpl |cap=A]] trailing) で opener 行 close、trailing は別要素。
  • 連続 include が独立にマッチ。
  • 未バランス opener は未展開のまま残る。
  • caption=[[[link]]] を含む multi-line include で link が完全に保持される。
  • triple-link が close と同一行隣接 (|cap=[[[link]]]]]) でも link 完全保持。
  • link 内の literal [[/]] が外側 directive close 判定に干渉しない。
  • 連続 directive (link 含む) が独立に解決。
  • lint / format / typecheck 通過。
  • include 系 62 pass / 全体テスト通過。

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 4, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
wdpr-demo-v1 fa2cff2 Commit Preview URL

Branch Preview URL
Jun 04 2026, 11:22 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 4, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
decompiler-preview fa2cff2 Commit Preview URL

Branch Preview URL
Jun 04 2026, 11:22 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 4, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
wdpr-demo-v1-files fa2cff2 Commit Preview URL

Branch Preview URL
Jun 04 2026, 11:22 AM

r74tech added 2 commits June 4, 2026 20:14
include パラメータ値に nested な [[ ... ]] (例: caption 内の
[[span]]...[[/span]]) や単独の ]] が含まれると、従来の正規表現が最初の
]] で directive を切ってしまい、値が途中で途切れて残りが外側に漏れていた。

INCLUDE_PATTERN を廃止し、scanIncludeDirectives に置換:
- [[ で depth+1、]] で depth-1 し、depth<=0 の ]] で close。
- ただし close と認めるのは「opener と同一行 (single-line/inline)」または
  「行末 (後続が空白のみ)」の ]] のみ。継続行の mid-line ]] (bare/nested)
  では閉じないため caption 等が途切れない。
- 同一行条件により inline-trailing ([[include x]] text) は opener 行で閉じ、
  後続の別 include を巻き込まない。
- close が見つからない opener は未展開のまま据え置き。
- expandIterative / expandIterativeAsync をスキャナベースに書き換え。

test: nested markup / bare ]] / single-line / inline-trailing + 後続 include /
triple-link(分離行) / 未バランス opener のケースを追加。
scanIncludeDirectives で `[[[ ... ]]]` を block の `[[`/`]]` とは別の
link depth で数えるよう変更。link depth が正のあいだは内部の `[[`/`]]`
を literal 扱いし block depth を動かさないため、link の `]]]` が directive
の close `]]` と同一行で隣接 (`...|cap=[[[link]]]]]`) しても link が
途切れず再構成される。directive の close 判定は従来どおり block depth の
opener 行 / 行末ルールのみに依存し、隣接する別 directive を巻き込まない。
@r74tech
r74tech force-pushed the fix/include-nested-bracket-balance branch from 277ac35 to fa2cff2 Compare June 4, 2026 11:22
@r74tech
r74tech merged commit ace0dfa into develop Jun 4, 2026
8 checks passed
@r74tech
r74tech deleted the fix/include-nested-bracket-balance branch June 4, 2026 11:22
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.

1 participant