Repository navigation
fix: keep values escaped in indented standalone partials - #701
Open
nadrummond wants to merge 1 commit into
Open
nadrummond wants to merge 1 commit into
nadrummond wants to merge 1 commit into
Conversation
An indented standalone partial renders into a temporary writer so each line can be indented. That writer was created with encoding suppressed, and the captured text is written on without encoding, so the partial's values were never escaped. The temporary writer now takes the caller's SuppressEncoding, as the partial would without indentation. 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.
Fixes #699.
Since #635, a partial whose tag stands alone on an indented line renders into a temporary writer, so
that
WriteWithIndentcan indent each line of its output. That writer was created withsuppressEncoding: true, andWriteWithIndentwrites the captured text withencode: false, so thepartial's values were never HTML-escaped. With
pregistered as[{{v}}]andvset to<b>&,<div>\n {{> p}}\n</div>rendered<div>\n [<b>&]</div>, while the same call inline or atcolumn 0 was escaped.
The temporary writer now takes the caller's
writer.SuppressEncoding, in all four indentationbranches of
PartialBinder:InvokePartialWithFallback, and the@partial-block, inline-partialand registered-template branches of
InvokePartial. Each of those branches, without indentation,renders through the caller's writer, so an indented partial now encodes exactly as an unindented one
does. The indentation itself is unchanged, and so is the output with
NoEscape = true.Tests
Added to the partial-indentation tests in
PartialTests:PartialIndentationKeepsValuesEscaped, a theory over an indented registered partial, an indented{{> @partial-block}}, and an indented call to a missing partial that falls back to the partialblock. Each expects
<div>\n [<b>&]</div>.InlinePartialIndentationKeepsValuesEscaped, for an indented call to a{{#*inline}}partial.PartialIndentationKeepsNoEscape, which checks that withNoEscape = truethe indented partialstays unescaped and keeps its indentation.
Without the change in
PartialBinder, the four escaping cases fail (Actual: "<div>\n [<b>&]</div>")and the
NoEscapecase passes. With it, the whole suite passes on net10.0: 2,331 tests, 0 failed.