Skip to content

schnauzer: Disable Strict Mode Checking for Boolean Operators #503

@cbgbt

Description

@cbgbt

What I'd like:
We should disable "strict" check for, at minimum, the following builtin "handlebars helpers":

  • eq
  • ne
  • and
  • or
  • not
  • others?

Background:
When schnauzer renders a template, it enables "strict mode" in our handlebars templating library. This causes templates to fail to render if they refer to context variables that are unset.

BUT that's only true under specific conditions (and in our case, some pretty inconvenient ones.)

Consider these scenarios:

{{#if settings.variable-that-doesnt-exist }}
hello!
{{else}}
goodbye!
{{/if}}

This will happily render as goodbye!; however, now consider this template:

{{#if (eq settings.variable-that-doesnt-exist "eleven") }}
hello!
{{else}}
goodbye!
{{/if}}

This does not render as goodbye! as you might expect, but instead fails to render entirely!

In handlebars parlance, if and eq are both "helpers". The "strict mode" setting in our handlebars library defers the strictness check to each setting implementation, rather than implementing it in a centralized location in the library.

This means that it depends entirely on how a helper is defined as to whether or not a strictness check occurs. In particular in the case of if and eq, they are implemented using different strategies in handlebars-rs.

In handlebars-rs, a helper is something that implements the HelperDef trait.

You can either manually define it using impl HelperDef for Type { ... }, or you can use a macro that the library provides called handlebars_helper! to generate an implementation on your behalf.

The eq helper is defined using the handlebars_helper! macro here. That macro's generated HelperDef checks if the handlebars registry has strict_mode enabled, and causes an error if the value is undefined.

The if helper uses a literal implementation of the HelperDef trait which does not interact with strict_mode. (and I have tests that prove it!)

I have half of an implementation of the idea for a fix here, but don't have time to carry it across the finish line, so leaving it in this issue for now: develop...cbgbt:bottlerocket-core-kit:schnauzer-custom-bools

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