Repository navigation
fix: match Handlebars.js for quoted-string paths, numeric partial names and {{#.}} sections - #703
Open
stencil-harness[bot] wants to merge 4 commits into
Open
stencil-harness[bot] wants to merge 4 commits into
stencil-harness[bot] wants to merge 4 commits into
Conversation
Undelimited partial names were typed as int/bool literals and failed with InvalidCastException at render time; use their text as the partial name, as Handlebars.js does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
{{#.}} failed to compile; treat it like {{#this}}, as Handlebars.js does.
Also exposes the registered-helper check for reuse.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A mustache containing only a quoted string always rendered empty. Handlebars.js resolves it as a single literal path segment; do the same by rewriting it to the equivalent segment literal. Raw blocks are unaffected because the rewrite runs after raw content is collected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…emaining gaps
Adds coverage for quoted-string paths, numeric partial names and {{#.}}
sections, and records the zero-valued section and explicit helperMissing
call differences as known gaps with regression tests.
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.



Refs #702. This fixes three of the six Handlebars.js 4.7.10 spec differences reported there. The other three are written up as known gaps and need a maintainer decision, so the issue stays open.
Fixed
{{'a\b'}}{ "a\b": "c" }""c{{'foo bar'}}/{{"foo bar"}}{ "foo bar": "baz" }""bazDudes: {{> 404}}404={{name}},name=JeepersInvalidCastExceptionDudes: Jeepers{{#.}}{{name}}{{/.}}×3[{name:"John Doe"},{name:"Jane Doe"}]HandlebarsCompilerExceptionJohn DoeJane Doe×3The before and after values come from running these templates against
master(2939312) and against this branch.LoneStringLiteralConverter, new):PathBinderevaluated a mustache whose only content is a string literal and then threw the value away, so{{'…'}}always rendered empty. Handlebars.js treats{{"foo bar"}}as the one-segment path[foo bar]. The new converter rewrites the literal to exactly that: it becomes a helper call when a helper with that name is registered, and a property lookup otherwise.{{'a.b'}}looks up the keya.band does not walk the nested path. The converter runs afterRawHelperAccumulator, so{{{{raw}}}}{{'x'}}{{{{/raw}}}}still outputs the text verbatim. Two kinds of literal are left alone, empty ones and ones containing], because neither can be written as a segment literal.PartialConverter): undelimited names such as404ortruehad been converted toint/boolconstants and then cast tostring. Their invariant-culture text is now used as the partial name.{{#.}}/{{^.}}(HelperConverter): these are accepted as block openers in the same way as{{#this}}/{{^this}}.Backward compatibility
{{#.}}fixes only affect templates that currently throw.{{'x'}}used to render nothing. It now renders the value ofxfrom the model, or calls a registered helperx. Because the old output was always empty, any template using this form intentionally was already broken. I think a patch release is reasonable, but this is the one item to check.Not changed (documented as gaps in
HandlebarsSpec.md, Gaps 5 and 6)The current behavior is locked in by regression tests
Section_ZeroValueSkipsBlock_SpecGapandHelperMissing_ExplicitCallRendersEmpty_SpecGap.{{#foo}}withfoo = 0. Handlebars.js renders the block with0as the context (This is ~). Handlebars.Net skips it (""). Changing this would break templates like{{#unreadCount}}You have {{.}} new messages{{/unreadCount}}, which currently render nothing at 0 and would start renderingYou have 0 new messages. Recommendation: leave it as is, or add an opt-in compatibility flag. Changing the default would need a major version.{{helperMissing}}/{{#helperMissing}}{{/helperMissing}}. Handlebars.js throws unlessallowExplicitCallOfHelperMissingis set. Handlebars.Net renders"". Throwing by default would break templates that call a custom missing-helper hook directly. With the default hooks a direct call renders nothing, so the security reason behind the JS restriction has little force here. Recommendation: document it as an intentional difference. If parity is wanted, add an opt-in option (minor version).Verification
dotnet test source/Handlebars.Test/Handlebars.Test.csproj: 2384 passed, 0 failed. Each new test runs against all fiveHandlebarsEnvGeneratorconfigurations.dotnet build source/Handlebars/Handlebars.csprojsucceeds for netstandard2.0, netstandard2.1, net8.0 and net10.0.No existing open PR or branch was linked to #702.
🤖 Generated with Claude Code
Closes #702