From d57003f1ac17764cdf6c159fe8533d2b88ffb821 Mon Sep 17 00:00:00 2001 From: Nikita Kotlyarov Date: Sun, 23 Jan 2022 12:43:26 +0400 Subject: [PATCH 1/2] Enable support for chained path iterators Fix issue #442 --- .../Handlebars.Test/BasicIntegrationTests.cs | 19 +++++++++++++++++++ source/Handlebars/PathStructure/PathInfo.cs | 1 - 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/source/Handlebars.Test/BasicIntegrationTests.cs b/source/Handlebars.Test/BasicIntegrationTests.cs index 00a4049f..621056cf 100644 --- a/source/Handlebars.Test/BasicIntegrationTests.cs +++ b/source/Handlebars.Test/BasicIntegrationTests.cs @@ -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 { diff --git a/source/Handlebars/PathStructure/PathInfo.cs b/source/Handlebars/PathStructure/PathInfo.cs index f39d344f..8dc57396 100644 --- a/source/Handlebars/PathStructure/PathInfo.cs +++ b/source/Handlebars/PathStructure/PathInfo.cs @@ -189,7 +189,6 @@ public static PathInfo Parse(string path) } var chainSegments = GetPathChain(segment); - if (chainSegments.Length > 1) isValidHelperLiteral = false; segments.Add(new PathSegment(segment, chainSegments)); } From 370a3a6f9db50353db498db260b0ce2f06571ddd Mon Sep 17 00:00:00 2001 From: Nikita Kotlyarov Date: Sun, 23 Jan 2022 13:02:24 +0400 Subject: [PATCH 2/2] Fix condition --- source/Handlebars/PathStructure/PathInfo.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/Handlebars/PathStructure/PathInfo.cs b/source/Handlebars/PathStructure/PathInfo.cs index 8dc57396..06f08041 100644 --- a/source/Handlebars/PathStructure/PathInfo.cs +++ b/source/Handlebars/PathStructure/PathInfo.cs @@ -190,6 +190,8 @@ public static PathInfo Parse(string path) var chainSegments = GetPathChain(segment); + if (chainSegments.Length > 1 && pathType != PathType.BlockHelper) isValidHelperLiteral = false; + segments.Add(new PathSegment(segment, chainSegments)); }