From 9c68fd3bb14743a9306c029dafe8db473c9900d0 Mon Sep 17 00:00:00 2001 From: Hoeksema <7414068+Hoeksema@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:18:13 +0100 Subject: [PATCH 1/2] Update WordParser.cs --- .../Compiler/Lexer/Parsers/WordParser.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/source/Handlebars/Compiler/Lexer/Parsers/WordParser.cs b/source/Handlebars/Compiler/Lexer/Parsers/WordParser.cs index 32800c64..64974024 100644 --- a/source/Handlebars/Compiler/Lexer/Parsers/WordParser.cs +++ b/source/Handlebars/Compiler/Lexer/Parsers/WordParser.cs @@ -44,16 +44,7 @@ private static string AccumulateWord(ExtendedStringReader reader) while (true) { - if (isEscaped) - { - var c = (char) reader.Read(); - if (c == ']') isEscaped = false; - - buffer.Append(c); - continue; - } - - if (!inString) + if (!inString && !isEscaped) { var peek = (char) reader.Peek(); @@ -70,6 +61,15 @@ private static string AccumulateWord(ExtendedStringReader reader) throw new HandlebarsParserException("Reached end of template before the expression was closed.", reader.GetContext()); } + if (isEscaped) + { + var c = (char) node; + if (c == ']') isEscaped = false; + + buffer.Append(c); + continue; + } + if (node == '[' && !inString) { isEscaped = true; From ff0844ca1fbc46c5b2f327007f12242ee48fc7ea Mon Sep 17 00:00:00 2001 From: Hoeksema <7414068+Hoeksema@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:20:54 +0100 Subject: [PATCH 2/2] Update ExceptionTests.cs --- source/Handlebars.Test/ExceptionTests.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/Handlebars.Test/ExceptionTests.cs b/source/Handlebars.Test/ExceptionTests.cs index 434dc999..0adea91a 100644 --- a/source/Handlebars.Test/ExceptionTests.cs +++ b/source/Handlebars.Test/ExceptionTests.cs @@ -57,5 +57,14 @@ public void TestLooseClosingBlockInIteratorExpressionException() Handlebars.Compile("{{#each enumerateMe}}test{{/if}}{{/each}}")(data); }); } + + [Fact] + public void TestNonClosingIgnoreBlockException() + { + Assert.Throws(() => + { + Handlebars.Compile("{{ [test }}")(new { }); + }); + } } }