Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions source/Handlebars.Test/IssueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,27 @@ public void UnrecognisedExpressionThrowsOutOfMemoryException()
Assert.Throws<HandlebarsCompilerException>(()=> Handlebars.Compile(source));
}

// Issue: https://github.com/Handlebars-Net/Handlebars.Net/issues/539
// Parent context (../) resolves to wrong value inside a custom block helper used within #each
[Fact]
public void Issue539_ParentContextInsideCustomBlockHelperInEach()
{
var handlebars = Handlebars.Create();
handlebars.RegisterHelper("ifCond", (writer, options, context, parameters) =>
{
if (parameters.Length == 3 && parameters[0]?.ToString() == parameters[2]?.ToString())
options.Template(writer, context);
else
options.Inverse(writer, context);
});

var source = @"{{#each loop}}{{#ifCond another '===' 'value'}}{{../this.foo}}{{/ifCond}}{{/each}}";
var template = handlebars.Compile(source);
var data = new { foo = "bar", loop = new object[] { new { another = "value" } } };
var result = template(data);
Assert.Equal("bar", result.Trim());
}

// Issue: https://github.com/Handlebars-Net/Handlebars.Net/issues/584
[Fact]
public void Issue584_EscapedDoubleQuoteInHelperStringArgument()
Expand Down
4 changes: 2 additions & 2 deletions source/Handlebars/BlockHelperOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public BindingContext Frame { get; }

public readonly ChainSegment[] BlockVariables;

Check warning on line 19 in source/Handlebars/BlockHelperOptions.cs

View workflow job for this annotation

GitHub Actions / SonarCloud

Use an immutable collection or reduce the accessibility of the non-private readonly field 'BlockVariables'.

internal BlockHelperOptions(
PathInfo name,
Expand Down Expand Up @@ -71,7 +71,7 @@
/// BlockHelper body
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Template(in EncodedTextWriter writer, in Context context) => Template(writer, context.Value);
public void Template(in EncodedTextWriter writer, in Context context) => OriginalTemplate(writer, Frame);

/// <summary>
/// BlockHelper body
Expand Down Expand Up @@ -113,7 +113,7 @@
/// BlockHelper body
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Inverse(in EncodedTextWriter writer, in Context context) => Inverse(writer, context.Value);
public void Inverse(in EncodedTextWriter writer, in Context context) => OriginalInverse(writer, Frame);

/// <summary>
/// BlockHelper body
Expand Down
Loading