diff --git a/source/Handlebars.Test/PathInfoTests.cs b/source/Handlebars.Test/PathInfoTests.cs index f55b154a..9eb9fb06 100644 --- a/source/Handlebars.Test/PathInfoTests.cs +++ b/source/Handlebars.Test/PathInfoTests.cs @@ -50,6 +50,9 @@ public void DotPath() [InlineData("a/[b.c].[b/c]/d", new [] {"a", "[b.c].[b/c]", "d"})] [InlineData("a/[b/c]/d", new [] {"a", "[b/c]", "d"})] [InlineData("a/[b.c/d]/e", new [] {"a", "[b.c/d]", "e"})] + [InlineData("a/[b.c/d/e/f]/e", new [] {"a", "[b.c/d/e/f]", "e"})] + [InlineData("a/[a//b/c.d/e]/e", new [] {"a", "[a//b/c.d/e]", "e"})] + [InlineData("a/[b/c/d].[e/f/g]/h", new [] {"a", "[b/c/d].[e/f/g]", "h"})] public void SlashPath(string input, string[] expected) { var pathInfo = PathInfo.Parse(input); @@ -62,4 +65,4 @@ public void SlashPath(string input, string[] expected) } } } -} \ No newline at end of file +} diff --git a/source/Handlebars/PathStructure/PathInfo.cs b/source/Handlebars/PathStructure/PathInfo.cs index 06f08041..6acbfba8 100644 --- a/source/Handlebars/PathStructure/PathInfo.cs +++ b/source/Handlebars/PathStructure/PathInfo.cs @@ -148,6 +148,7 @@ public static PathInfo Parse(string path) var extendedEnumerator = ExtendedEnumerator.Create(pathParts); using var container = StringBuilderPool.Shared.Use(); var buffer = container.Value; + var bufferHasOpenEscapeBlock = false; while (extendedEnumerator.MoveNext()) { @@ -159,6 +160,7 @@ public static PathInfo Parse(string path) if(Substring.LastIndexOf(segment, ']', out var index) && !Substring.LastIndexOf(segment, '[', index, out _)) { + bufferHasOpenEscapeBlock = false; var chainSegment = GetPathChain(buffer.ToString()); if (chainSegment.Length > 1) isValidHelperLiteral = false; @@ -171,7 +173,8 @@ public static PathInfo Parse(string path) if(Substring.LastIndexOf(segment, '[', out var startIndex) && !Substring.LastIndexOf(segment, ']', startIndex, out _)) { - buffer.Append(in segment); + if (!bufferHasOpenEscapeBlock) buffer.Append(in segment); + bufferHasOpenEscapeBlock = true; continue; } @@ -192,7 +195,7 @@ public static PathInfo Parse(string path) if (chainSegments.Length > 1 && pathType != PathType.BlockHelper) isValidHelperLiteral = false; - segments.Add(new PathSegment(segment, chainSegments)); + if (!bufferHasOpenEscapeBlock) segments.Add(new PathSegment(segment, chainSegments)); } if (isValidHelperLiteral && segments.Count > 1) isValidHelperLiteral = false; @@ -252,4 +255,4 @@ private static PathType GetPathType(string path) }; } } -} \ No newline at end of file +}