You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Whitespace in opening Partial Block expression? #217
This currently throws an exception, (I'm using the latest bleeding-edge build, v1.9.0-ci, from commit: a56efe8 - I haven't tested any other version/release).
Reached end of template before block expression
[HandlebarsCompilerException: Reached end of template before block expression '' was closed]
HandlebarsDotNet.Compiler.BlockAccumulator.AccumulateBlock(IEnumerator`1 enumerator, BlockAccumulatorContext context) +411
HandlebarsDotNet.Compiler.<ConvertTokens>d__3.MoveNext() +389
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +333
System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
HandlebarsDotNet.Compiler.BlockAccumulator.Accumulate(IEnumerable`1 tokens, HandlebarsConfiguration configuration) +97
HandlebarsDotNet.Compiler.ExpressionBuilder.ConvertTokensToExpressions(IEnumerable`1 tokens) +268
HandlebarsDotNet.Compiler.HandlebarsCompiler.CompileView(String templatePath) +576
HandlebarsDotNet.HandlebarsEnvironment.CompileView(String templatePath) +101
The partial block expression works fine when the extra whitespace is removed. 🎉
{{#>myPartial}}
Failover content
{{/myPartial}}
Back story: It's my first time using this library today - thank you, it's great!! I'm totally happy to contribute back a PR for this one, if you have any pointers on where to look? (I'm currently digging around the Lexer/Parser classes.)
Allowing whitespace is definitely intended. The problem is that starting here and cascading down to this entire class, both are built to assume at this point in the pipeline, a #>name is a single WordToken. Inserting the space means that upstream, the base parsing phase of the lexer interprets it as two separate WordTokens: #> and name. These components choke when they see a #> word with extra characters to make up the name, and an extra, un-explainable word after it in the token sequence.
The correct way to solve this, to be consistent with how other similar constructs are handled, is probably to make the parser break between #> and the name so they are always two words, and then in the BlockAccumulators, search for a #> word followed by another word that can be assumed to be the name of the partial; and then combine those two into the partial block expression.
Activity
rexm commentedon Jul 1, 2017
Allowing whitespace is definitely intended. The problem is that starting here and cascading down to this entire class, both are built to assume at this point in the pipeline, a
#>nameis a singleWordToken. Inserting the space means that upstream, the base parsing phase of the lexer interprets it as two separate WordTokens:#>andname. These components choke when they see a#>word with extra characters to make up the name, and an extra, un-explainable word after it in the token sequence.The correct way to solve this, to be consistent with how other similar constructs are handled, is probably to make the parser break between
#>and the name so they are always two words, and then in the BlockAccumulators, search for a#>word followed by another word that can be assumed to be the name of the partial; and then combine those two into the partial block expression.PR definitely welcome!
arsu-leo commentedon Nov 3, 2020
Would be good to at least document this behaivour on the Readme on themeantime, it took me a lot of time to find out this issue
Fix whitespace support for partials