From 74a9395c2b703fdfb9f2b6339c6ca3136baabed4 Mon Sep 17 00:00:00 2001 From: Hoeksema <7414068+Hoeksema@users.noreply.github.com> Date: Wed, 14 Feb 2024 16:51:01 +0100 Subject: [PATCH 1/5] Update PathInfo.cs --- source/Handlebars/PathStructure/PathInfo.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/Handlebars/PathStructure/PathInfo.cs b/source/Handlebars/PathStructure/PathInfo.cs index 06f08041..c9124c46 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; @@ -172,6 +174,7 @@ public static PathInfo Parse(string path) && !Substring.LastIndexOf(segment, ']', startIndex, out _)) { 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 +} From c7d3097ba85c187b1f164479f6f16ceea724dbb8 Mon Sep 17 00:00:00 2001 From: Hoeksema <7414068+Hoeksema@users.noreply.github.com> Date: Wed, 14 Feb 2024 16:54:45 +0100 Subject: [PATCH 2/5] Update PathInfoTests.cs --- source/Handlebars.Test/PathInfoTests.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/Handlebars.Test/PathInfoTests.cs b/source/Handlebars.Test/PathInfoTests.cs index f55b154a..fcf39d5a 100644 --- a/source/Handlebars.Test/PathInfoTests.cs +++ b/source/Handlebars.Test/PathInfoTests.cs @@ -50,6 +50,8 @@ 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"})] public void SlashPath(string input, string[] expected) { var pathInfo = PathInfo.Parse(input); @@ -62,4 +64,4 @@ public void SlashPath(string input, string[] expected) } } } -} \ No newline at end of file +} From 33cffd33cce5b9c0cf3dfdd95d5bd07c783e2e79 Mon Sep 17 00:00:00 2001 From: Hoeksema <7414068+Hoeksema@users.noreply.github.com> Date: Wed, 14 Feb 2024 16:55:14 +0100 Subject: [PATCH 3/5] Update PathInfoTests.cs From ef443acefff21054fed5457c2c9181bcf38f4eb8 Mon Sep 17 00:00:00 2001 From: Hoeksema <7414068+Hoeksema@users.noreply.github.com> Date: Wed, 14 Feb 2024 17:45:00 +0100 Subject: [PATCH 4/5] missing case to avoid double buffer addition --- source/Handlebars/PathStructure/PathInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Handlebars/PathStructure/PathInfo.cs b/source/Handlebars/PathStructure/PathInfo.cs index c9124c46..6acbfba8 100644 --- a/source/Handlebars/PathStructure/PathInfo.cs +++ b/source/Handlebars/PathStructure/PathInfo.cs @@ -173,7 +173,7 @@ 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; } From dd45cbe3750b8cbe06beb78ffe2536d9b3f9296a Mon Sep 17 00:00:00 2001 From: Hoeksema <7414068+Hoeksema@users.noreply.github.com> Date: Wed, 14 Feb 2024 17:46:09 +0100 Subject: [PATCH 5/5] Update PathInfoTests.cs complete test coverage --- source/Handlebars.Test/PathInfoTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/source/Handlebars.Test/PathInfoTests.cs b/source/Handlebars.Test/PathInfoTests.cs index fcf39d5a..9eb9fb06 100644 --- a/source/Handlebars.Test/PathInfoTests.cs +++ b/source/Handlebars.Test/PathInfoTests.cs @@ -52,6 +52,7 @@ public void DotPath() [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);