Skip to content

[6.x] Restore Raw blocks in blade nocache views - #15365

Open
ryanmitchell wants to merge 1 commit into
statamic:6.xfrom
ryanmitchell:fix/issue-11987
Open

[6.x] Restore Raw blocks in blade nocache views#15365
ryanmitchell wants to merge 1 commit into
statamic:6.xfrom
ryanmitchell:fix/issue-11987

Conversation

@ryanmitchell

Copy link
Copy Markdown
Contributor

Fixes #11987

Not sure if this is the right way @JohnathonKoster but Claude seems to think so.

@JohnathonKoster

Copy link
Copy Markdown
Contributor

Similar to how I would have done it! Looks reasonable

Comment on lines +37 to +41
$rawBlocks = \Closure::bind(fn () => $this->rawBlocks, $compiler, BladeCompiler::class)();

if (empty($rawBlocks)) {
return $compiled;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PHP-vs-verbatim discriminator is a content-shape heuristic (str_starts_with($raw, '<?php') && str_ends_with($raw, '?>')), not a real type tag — Laravel's rawBlocks doesn't retain origin type. If a @verbatim block's trimmed content happens to itself be exactly <?php ... ?> (e.g. someone documenting Blade/PHP syntax verbatim), it will be misclassified as a passthrough PHP block and actually executed as PHP in the second compile pass instead of rendered as literal text. Narrow edge case, template-author-controlled content (not a remote-attacker vector), but it's a genuine logic bug in new code, not pre-existing. No test covers this collision case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fix would mean shielding @php/@verbatim blocks inside statamic:nocache regions before Laravel's own storeUncompiledBlocks() runs which requires subclassing BladeCompiler and rebinding the blade.compiler container singleton so we can intercept ahead of parent::compileString().

Given it's template-author-controlled content and requires deliberately writing verbatim content that's byte-for-byte an empty PHP tag pair, could we document the limitation in a comment for now and come back to the bigger change if required down the line?

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.

Blade <statamic:nocache> undefined variable

3 participants