Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
oformaniuk authored Apr 1, 2024
2 parents 667b081 + dd9c16f commit 435296b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
9 changes: 9 additions & 0 deletions source/Handlebars.Test/ExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,14 @@ public void TestLooseClosingBlockInIteratorExpressionException()
Handlebars.Compile("{{#each enumerateMe}}test{{/if}}{{/each}}")(data);
});
}

[Fact]
public void TestNonClosingIgnoreBlockException()
{
Assert.Throws<HandlebarsParserException>(() =>
{
Handlebars.Compile("{{ [test }}")(new { });
});
}
}
}
20 changes: 10 additions & 10 deletions source/Handlebars/Compiler/Lexer/Parsers/WordParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
Expand Down

0 comments on commit 435296b

Please sign in to comment.