Skip to content

Parselet::ParseFailed error due to leading/trailing space inside closing expression to if block helper #29

@jmpage

Description

@jmpage

If a leading/trailing space is present inside the opening/closing expression of a an if-block helper, a Parselet::ParseFailed error will be raised during compilation of the template when using ruby-handlebars v0.4.0 and parselet v1.8.2.

Handlebars::Handlebars.new.compile(<<~TEMPLATE.strip)
  {{ #if foo}}
    Foo
  {{/if}}
TEMPLATE

Handlebars::Handlebars.new.compile(<<~TEMPLATE.strip)
  {{#if foo}}
    Foo
  {{/if }}
TEMPLATE

# Parslet::ParseFailed: Extra input after last repetition at line 1 char 1.
# from /usr/local/bundle/gems/parslet-1.8.2/lib/parslet/cause.rb:70:in `raise'

This seems to deviate from how handlebars-js handles templates in that trailing or leading spaces don't seem to adversely affect the canonical implementation. I'm aware that this gem isn't intended as a complete implementation of handlebars. Would you consider this an intentional design decision or would it be sensible to add space? to the parslet logic in parser.rb?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions