fix: subexpression WriteSafeString output not double-encoded (issue #543)#633
Merged
Conversation
…on boundary (issue #543) When a helper written with WriteSafeString was used as a subexpression argument, ReturnInvoke captured the output as a plain string, losing the "already-encoded" signal. The outer helper then re-encoded the content. Introduce an internal SafeString wrapper that ReturnInvoke now returns. EncodedTextWriter.Write<T>, WriteSafeString(object), HandlebarsUtils.IsFalsy, and PartialBinder all understand SafeString, so the value flows through without double-encoding while dynamic partial lookups continue to work. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
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 #543
Values written via
WriteSafeStringinside a subexpression are now passed to the outer helper without re-encoding.What changed
HelperExtensions.ReturnInvokecaptures a helper's writer output and returns it as the subexpression's value. Previously it returned a plainstring, losing the "already-encoded" signal — so the outer helper (or the partial resolver) would encode it a second time.The fix introduces an internal
SafeStringwrapper class.ReturnInvokenow wraps its result inSafeString, and the following sites handle it transparently:EncodedTextWriter.Write<T>— writesSafeString.Valuewithout encodingHandlebarsExtensions.WriteSafeString(object)— unwrapsSafeStringbefore writingHandlebarsUtils.IsFalsy— treatsSafeString("")as falsy, matching string semanticsPartialBinder— extracts the raw name string from aSafeStringwhen the partial name comes from a subexpression ({{> (helper)}})Tests
source/Handlebars.Test/Issues/Issue543Tests.csadds two regression tests covering the standalone and subexpression cases.All 1 748 existing tests continue to pass.