Repository navigation
In review
In review
Copy link
Description
Describe the bug
I ran a few examples from the Handlebars.js v4.7.10 spec against Handlebars.Net 2.5.0 (NuGet, assembly 2.5.0.0) and six of them come out differently. Current master (2939312) gives the same results.
| Template | Input | Handlebars.js 4.7.10 | Handlebars.Net 2.5.0 |
|---|---|---|---|
{{'a\b'}} |
key a\b = c |
c (security.js L442-L447) |
empty string |
Dudes: {{> 404}} |
name = Jeepers, partial 404 = {{name}} |
Dudes: Jeepers (partials.js L247-L253) |
InvalidCastException |
{{#.}}{{name}}{{/.}} three times |
array of two objects, names John Doe and Jane Doe |
John DoeJane Doe three times (regressions.js L97-L107, GH-408) |
HandlebarsCompilerException at compile |
{{#foo}} This is {{bar}} ~ {{/foo}} |
foo = 0, bar = OK |
This is ~ (regressions.js L185-L192, GH-731) |
empty string |
{{helperMissing}} |
empty object | throws (security.js L73-L75, GH-1558) | empty string |
{{#helperMissing}}{{/helperMissing}} |
empty object | throws (security.js L77-L79, GH-1558) | empty string |
The last two only apply when allowExplicitCallOfHelperMissing isn't set, which is the default.
Expected behavior:
The same output as Handlebars.js for these templates. If any of them are intentional differences, it'd be nice to have them listed with the other known gaps.
Test to reproduce
using HandlebarsDotNet;
void Run(string name, string template, object data, Dictionary<string, string>? partials = null)
{
try
{
var hb = Handlebars.Create();
if (partials != null)
foreach (var p in partials) hb.RegisterTemplate(p.Key, p.Value);
var output = hb.Compile(template)(data);
Console.WriteLine($"{name}: \"{output}\"");
}
catch (Exception e)
{
Console.WriteLine($"{name}: {e.GetType().Name}");
}
}
Run("escaped key", "{{'a\\b'}}", new Dictionary<string, object> { ["a\\b"] = "c" });
Run("numeric partial", "Dudes: {{> 404}}", new Dictionary<string, object> { ["name"] = "Jeepers" }, new() { ["404"] = "{{name}}" });
var people = new object[]
{
new Dictionary<string, object> { ["name"] = "John Doe" },
new Dictionary<string, object> { ["name"] = "Jane Doe" },
};
Run("dot sections", "{{#.}}{{name}}{{/.}}{{#.}}{{name}}{{/.}}{{#.}}{{name}}{{/.}}", people);
Run("zero section", "{{#foo}} This is {{bar}} ~ {{/foo}}", new Dictionary<string, object> { ["foo"] = 0, ["bar"] = "OK" });
Run("helperMissing inline", "{{helperMissing}}", new Dictionary<string, object>());
Run("helperMissing block", "{{#helperMissing}}{{/helperMissing}}", new Dictionary<string, object>());Output on 2.5.0:
escaped key: ""
numeric partial: InvalidCastException
dot sections: HandlebarsCompilerException
zero section: ""
helperMissing inline: ""
helperMissing block: ""
Other related info
.NET 8 SDK, Handlebars.Net 2.5.0 from NuGet.
Metadata
Metadata
Assignees
Labels
No labels
Activity
stencil-harness commentedon Nov 25, 2026
I'm the agent responsible for managing intake of issues, acting under @rexm's steering. I understand this reports six Handlebars.js 4.7.10 spec cases (escaped string-literal keys, numeric partial names, repeated
{{#.}}sections,0as a section value, and explicithelperMissingcalls) that behave differently in Handlebars.Net; I'll reproduce each one and evaluate which I can safely fix autonomously.stencil-harness commentedon Nov 25, 2026
I've opened #703 to fix three of the six cases. The other three are listed as known gaps and need a decision from a maintainer.
Fixed in #703 (Handlebars-Net/Handlebars.Net, branch
robot/issue-702; not merged or released yet):{{'a\b'}}now rendersc. Before the fix, any mustache containing only a quoted string rendered empty. It is now resolved the same way as{{[a\b]}}, which matches Handlebars.js.Dudes: {{> 404}}now rendersDudes: Jeepers. It used to throwInvalidCastException.{{#.}}{{name}}{{/.}}repeated three times now rendersJohn DoeJane Doethree times. It used to throwHandlebarsCompilerException.Left as they are, now listed as known gaps (Gaps 5 and 6 in
HandlebarsSpec.md):{{#foo}}withfoo = 0renders"", where Handlebars.js rendersThis is ~. Matching Handlebars.js would make templates like{{#unreadCount}}You have {{.}} new messages{{/unreadCount}}start printing "You have 0 new messages". My recommendation is an opt-in flag at most; changing the default would need a major version.{{helperMissing}}or{{#helperMissing}}{{/helperMissing}}renders"", where Handlebars.js throws. Throwing by default would break templates that call a custom missing-helper hook directly. My recommendation is to document this as an intentional difference, or to add an opt-in option (minor version).How I checked: I ran all six of your templates against
masterand got the output you reported, then ran them against the branch. The full test suite passes (2384 tests, 0 failures) and the library builds for every target framework. The PR isMERGEABLEand is waiting on review and checks.