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 { }); + }); + } } } 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;