Skip to content

Whitespace in opening Partial Block expression? #217

Closed
dotnet/arcade
#16884

Description

@leekelleher

Reading from the Handlebars specs, the opening Partial Block expressions appear to allow whitespace.

http://handlebarsjs.com/partials.html#partial-block

{{#> myPartial }}
  Failover content
{{/myPartial}}

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.)

Thanks!

Activity

  1. rexm commented on Jul 1, 2017

    @rexm
    Member

    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.

    PR definitely welcome!

  2. arsu-leo commented on Nov 3, 2020

    @arsu-leo

    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

  3. added a commit that references this issue on Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions