Repository navigation
fix: chain {{else helper ...}} under {{#if}} and {{#unless}} - #684
Open
EnesKartal wants to merge 1 commit into
Open
EnesKartal wants to merge 1 commit into
EnesKartal wants to merge 1 commit into
Conversation
The if/unless context handled every chained else itself, but only understood a two-argument {{else if x}}. {{else ifEq b "x"}} was taken as a plain {{else}}, which dropped its condition and made a following {{else}} throw ArgumentNullException at compile time, and a two-argument {{else with b}} was evaluated as {{else if b}}.
The context now only keeps {{else if x}} and {{else unless x}} for itself. Any other {{else name ...}} is desugared into a nested block by BlockAccumulator, as for other block helpers. {{else unless x}} is now negated, and {{else if}} / {{else unless}} with the wrong number of arguments throw HandlebarsCompilerException like {{#if}} / {{#unless}}.
Fixes Handlebars-Net#683
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 #683.
ConditionalBlockAccumulatorContexthandled every chained{{else ...}}itself, but only recognised a two-argument{{else if x}}:{{#if a}}A{{else ifEq b "x"}}B{{else}}C{{/if}}took{{else ifEq b "x"}}as a plain{{else}}, so the next{{else}}builtExpression.IfThen(null, ...)andCompilethrewArgumentNullException (Parameter 'test').{{else}}theifEqcondition was silently dropped andBalways rendered.{{else with b}}was evaluated as{{else if b}}.{{else unless x}}under{{#if}}was evaluated as{{else if x}}(the condition was not negated).Change
HandlesChainedElseInternallybecomesHandlesChainedElse(item). The if/unless context returns true only for{{else if ...}}and{{else unless ...}}. Any other{{else name ...}}goes through the desugaring from feat: support else-if chaining for block helpers #648, the same as under other block helpers.{{else unless x}}is negated.{{else if}}/{{else unless}}with the wrong number of arguments now throwHandlebarsCompilerException("#if requires exactly one argument"), like{{#if}}/{{#unless}}since fix: throw HandlebarsCompilerException for #if/#unless with wrong argument count #678.AccumulatedBlockwithout passing the closing tag to the outer context, so the conditional context now builds its last branch inAccumulatedBlockfrom the buffer instead of inIsClosingElement. The result is the same expression as before for templates that were already supported.Test plan
New tests next to the #263 chained-else tests in
IssueTests, plus twoInlineDatarows inExceptionTests.TestConditionalBlockWithWrongArgumentCountException.Before the fix (
dotnet test --filter ..., library changes stashed):After the fix, whole test project:
dotnet build source/Handlebars/Handlebars.csproj -f netstandard2.0also builds.