Skip to content

Commit

Permalink
Merge pull request #488 from abraham-fox/enable-support-for-chained-p…
Browse files Browse the repository at this point in the history
…ath-iterators

Enable support for chained path iterators
  • Loading branch information
oformaniuk authored Jan 23, 2022
2 parents 4277ab1 + 370a3a6 commit bf2925d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 19 additions & 0 deletions source/Handlebars.Test/BasicIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2044,6 +2044,25 @@ public void HtmlEncoderCompatibilityIntegration_LateChangeConfig(bool useLegacyH

Assert.Equal(expected, actual);
}

[Fact]
public void ChainedPathIteratorHelper()
{
var context = new
{
bundles = new
{
styles = new
{
vendor = new[] { "a", "b", "c" }
}
}
};

var nestedObjectsHelperResult = Handlebars.Compile("{{#bundles.styles.vendor}}{{this}}{{/bundles.styles.vendor}}")(context);

Assert.Equal("abc", nestedObjectsHelperResult);
}

private class StringHelperResolver : IHelperResolver
{
Expand Down
3 changes: 2 additions & 1 deletion source/Handlebars/PathStructure/PathInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ public static PathInfo Parse(string path)
}

var chainSegments = GetPathChain(segment);
if (chainSegments.Length > 1) isValidHelperLiteral = false;

if (chainSegments.Length > 1 && pathType != PathType.BlockHelper) isValidHelperLiteral = false;

segments.Add(new PathSegment(segment, chainSegments));
}
Expand Down

0 comments on commit bf2925d

Please sign in to comment.