Skip to content

fix(parser): [[include]] 末尾の余分な ] を許容して terminator を見つける#48

Merged
r74tech merged 1 commit into
developfrom
fix/include-multiline-tail-bug
Jun 5, 2026
Merged

fix(parser): [[include]] 末尾の余分な ] を許容して terminator を見つける#48
r74tech merged 1 commit into
developfrom
fix/include-multiline-tail-bug

Conversation

@r74tech

@r74tech r74tech commented Jun 5, 2026

Copy link
Copy Markdown
Owner

背景

最後の引数値が ] で終わる multi-line include — 例えば [[include foo\n|key=val|bar=--]|]] の改行省略形 [[include foo\n|key=val|bar=--]]] — で scanIncludeDirectives が terminator を見つけられず、include ディレクティブ全体が生テキストとして残ってしまっていた。

原因は isRestOfLineBlank の判定。]] で depth が 0 になった時点で「直後が空白+改行なら terminator」と判定するが、]]] のように直後に ] が漏れ出ているケースでは「空白ではない」として close を拒否し、ループが closeEnd を見つけられないまま directive を諦めていた。

変更点

isRestOfLineBlank の終端判定で ] も whitespace と同様に skip する。これにより:

  • [[include tmpl\n|cap= --]]]<<-->>] (]] で directive close、余分な ] は include 外の raw text として残る)
  • [[include tmpl\n|cap= --]]]\n\nafter<<-->>]\n\nafter
  • [[include tmpl\n|cap= x]]]]]<<x>>]]]

inline include ([[include foo |arg=val]]) や、attribute 内に [[span]]...[[/span]] を含むケース、[[[link]]] を含むケースには影響なし。

後方互換性

]] を見つけた瞬間に terminator として close する条件が緩和されるだけで、既存の close 条件 (opener-line または完全な行末 blank) でも従来通り close される。逆に既存の close 条件で raw text 化していたケースだけが新たに resolve されるようになるため、既存挙動への影響はない。

Test plan

  • bun run lint (10 warnings, 0 errors — 既存箇所のみ)
  • bun run format
  • bun run typecheck
  • bun test (1295 pass / 0 fail)
  • 新規テスト 3 ケース (tests/unit/module/include/resolve.test.ts):
    • terminating ]] の直後に stray ] がある multi-line include
    • 上記 + 続けて他のコンテンツがある場合
    • stray ] が複数連続する場合
  • release 後、wpv4 を bump して実ページで include が解決されることを確認

最後の引数値が `]` で終わる multi-line include
(例: `[[include foo\n|key=val|bar=--]|]]` の改行省略形である
`[[include foo\n|key=val|bar=--]]]`) で、scanIncludeDirectives が
「行末 blank ではない」と判定して terminator を見つけられず、
include 全体を生テキストとして残していた。

isRestOfLineBlank が行末判定で `]` も whitespace と同様に skip する
よう修正。終端 `]]` で directive を close し、余分な `]` は include
外の raw text として残る。
@cloudflare-workers-and-pages

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 1c47366 Commit Preview URL

Branch Preview URL
Jun 05 2026, 08:45 AM

@cloudflare-workers-and-pages

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 1c47366 Commit Preview URL

Branch Preview URL
Jun 05 2026, 08:45 AM

@cloudflare-workers-and-pages

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 1c47366 Commit Preview URL

Branch Preview URL
Jun 05 2026, 08:45 AM

@r74tech
r74tech merged commit 38c4bea into develop Jun 5, 2026
9 checks passed
@r74tech
r74tech deleted the fix/include-multiline-tail-bug branch June 5, 2026 08:48
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