Skip to content

Raw block helpers fail to compile when Compatibility.RelaxedHelperNaming is enabled #676

Closed

Description

@stencil-harness

Describe the bug

With Compatibility.RelaxedHelperNaming = true, no raw block helper compiles, not even an empty one. Compilation throws:

HandlebarsCompilerException: Reached end of template before raw block helper expression 'raw' was closed

The same templates compile and render correctly with the default setting (false).

To reproduce

var hbs = Handlebars.Create();
hbs.Configuration.Compatibility.RelaxedHelperNaming = true;
hbs.RegisterHelper("raw", (writer, options, context, arguments) => options.Template(writer, context));

hbs.Compile("{{{{raw}}}}{{{{/raw}}}}");          // throws
hbs.Compile("{{{{raw}}}}a{{foo}}b{{{{/raw}}}}"); // throws
Template RelaxedHelperNaming = false RelaxedHelperNaming = true
{{{{raw}}}}{{{{/raw}}}} "" throws
{{{{raw}}}}a{{foo}}b{{{{/raw}}}} "a{{foo}}b" throws

Likely cause

The closing raw tag is mistaken for the start of a block helper.

  • HelperConverter.IsUnregisteredBlockHelperName (source/Handlebars/Compiler/Lexer/Converter/HelperConverter.cs) checks the closing word /raw from {{{{/raw}}}}.
  • With the default setting, /raw fails the IsValidHelperLiteral check and is left as a plain word. With RelaxedHelperNaming on, that check is skipped.
  • Inside raw tags, the !isRaw && ... guard doesn't apply either. Unlike IsRegisteredHelperName and IsRegisteredBlockHelperName, this method never rejects pathInfo.IsBlockClose.
  • It strips the first character (/raw → raw), looks for /raw in the template, finds the very tag it is checking, and turns that closing tag into a HelperExpression.
  • RawHelperAccumulator.IsClosingTag only recognizes a WordExpressionToken with the value /raw. So the closing tag is never found and the accumulator reaches the end of the template.

A likely fix is to add if (pathInfo.IsBlockClose) return false; to IsUnregisteredBlockHelperName, as the other two checks already do. This needs a regression test that runs raw blocks with RelaxedHelperNaming both on and off.

Context

Found while working on #672. It exists on master and is unrelated to that change.

Activity

  1. rexm commented on Nov 7, 2026

    @rexm
    Member

    /harness adopt

  2. stencil-harness commented on Nov 7, 2026

    @stencil-harness
    ContributorAuthor

    I'm the agent handling issue intake on Rex's behalf. I understand this as: with Compatibility.RelaxedHelperNaming = true, raw block helpers ({{{{raw}}}}...{{{{/raw}}}}) fail to compile because the closing tag is misread as a block helper opener. I'll evaluate whether I can fix this autonomously.

  3. stencil-harness commented on Nov 7, 2026

    @stencil-harness
    ContributorAuthor

    Fixed on branch claude/issue-676. It has not been merged or released.

    Handlebars-Net/Handlebars.Net (the only repo changed)

    • HelperConverter.IsUnregisteredBlockHelperName now returns false for block-close paths (/name), the same way IsRegisteredHelperName and IsRegisteredBlockHelperName already do. Before this, with RelaxedHelperNaming = true, the {{{{/raw}}}} closing tag was turned into a block helper expression. RawHelperAccumulator then never found the closing tag, so compilation failed.
    • Behavior with the default setting is unchanged. A /name word only reached this check inside raw tags with relaxed naming turned on, which is exactly the case that was broken.

    Verification

    • Added RawHelperTests.RawBlockHelperCompilesRegardlessOfRelaxedHelperNaming. It covers empty raw blocks, raw blocks with a mustache body, nested raw tags, and raw blocks with arguments, each with RelaxedHelperNaming both off and on. Before the fix the 4 relaxed cases failed and the 4 default cases passed.
    • After the fix the full test suite passes: 2193 passed, 0 failed.

    Shipped: nothing. The work is staged on the branch for a maintainer to review and merge.

  4. rexm commented on Nov 7, 2026

    @rexm
    Member

    /harness ship

  5. stencil-harness commented on Nov 7, 2026

    @stencil-harness
    ContributorAuthor

    I opened #677 to ship the fix.

    Handlebars-Net/Handlebars.Net (the only repo changed): I opened #677 from claude/issue-676 and requested auto-merge. GitHub will merge it into master once the required checks pass; it has not landed yet.

    • Change: HelperConverter.IsUnregisteredBlockHelperName now rejects block-close paths. This means {{{{/raw}}}} is no longer read as the start of a block helper when RelaxedHelperNaming is on. Behavior with the default setting is unchanged.
    • Verification: the new tests in RawHelperTests.RawBlockHelperCompilesRegardlessOfRelaxedHelperNaming cover raw blocks with the setting both off and on. Before the fix the 4 relaxed cases failed. After it the full suite passes (2193 passed, 0 failed).

    No NuGet release has been cut. Publishing a new version is a separate maintainer step.

  6. added a commit that references this issue on Nov 7, 2026
    0109dae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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