Repository navigation
fix: HTML-escape values in indented standalone partials - #700
Open
stencil-harness[bot] wants to merge 2 commits into
Open
stencil-harness[bot] wants to merge 2 commits into
stencil-harness[bot] wants to merge 2 commits into
Conversation
The indented-partial rendering paths (registered, inline, @partial-block and
partial-block fallback) buffered output through an EncodedTextWriter created
with suppressEncoding: true, so {{value}} inside an indented partial was
written raw. The buffer now inherits the outer writer's SuppressEncoding,
matching the non-indented path (and still honoring NoEscape / triple-stash).
Fixes #699
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Exercise the missing-partial fallback branch with an actual indent, add a nested-partial case and the reproduction from the issue report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This branch has not been deployed
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.



Problem
Since 2.2.0 (#635, the fix for #614), a standalone partial tag on an indented line writes its values without HTML escaping. The same partial called inline, or on its own line at column 0, is escaped. Repro from #699:
To indent each line,
PartialBinderrenders the partial into a temporary writer and then passes the captured text toWriteWithIndent. That temporary writer was created withsuppressEncoding: true, andWriteWithIndentwrites withencode: false, so nothing on that path encoded. The same argument was used in all four indentation branches:InvokePartialWithFallback, plus the@partial-block, inline-partial and registered-template branches ofInvokePartial. Everything the indented partial rendered was unescaped, including partials it called itself.Fix
The temporary writer now takes the caller's
writer.SuppressEncodinginstead oftrue. Indented partials therefore escape exactly as the non-indented path does, which renders through the caller's writer.{{{triple}}}output andConfiguration.NoEscape = truestill produce unescaped output, as before.Thanks to @nadrummond for the analysis in #699, which identifies the same root cause and fix.
Tests
New tests in
PartialTests:IndentedPartialEscapesValues: covers a registered partial, an inline partial,@partial-block, the missing-partial fallback to the partial block, and an indented partial that calls another partialPartialIndentationKeepsValuesEscaped: the repro from the issueIndentedPartialMatchesUnindentedEscaping: indented and non-indented output agree, and triple-stash stays rawIndentedPartialHonorsNoEscape7 of the 8 new tests fail against the current
mastercode (only theNoEscapetest passes there, as expected), and all pass with the fix. Full suite: 2352 passed, 0 failed.Compatibility / release
This puts back the escaping that 2.1.x had and that non-indented partials still have. Templates that rely on the 2.2.0–2.5.0 unescaped output inside indented partials will now get escaped output. That output was a bug and a potential XSS vector, not a feature. Such templates should use
{{{ }}}, exactly as they would need to for a non-indented partial. Recommend a patch release (2.5.1).Fixes #699
🤖 Generated with Claude Code
Closes #699