diff --git a/source/Handlebars.Test/IssueTests.cs b/source/Handlebars.Test/IssueTests.cs index 6c1402d7..31136117 100644 --- a/source/Handlebars.Test/IssueTests.cs +++ b/source/Handlebars.Test/IssueTests.cs @@ -723,5 +723,15 @@ public void LastLetterCutOff() Assert.Equal("abcd", templateOutput); } + + // Issue: https://github.com/Handlebars-Net/Handlebars.Net/issues/535 + // Issue refers to invalid template causing OutOfMemoryException + [Fact] + public void UnrecognisedExpressionThrowsOutOfMemoryException() + { + var source = "{{Name | invalid}}"; + + Assert.Throws(()=> Handlebars.Compile(source)); + } } } \ No newline at end of file diff --git a/source/Handlebars/Compiler/Lexer/Parsers/BlockParamsParser.cs b/source/Handlebars/Compiler/Lexer/Parsers/BlockParamsParser.cs index 4b861705..aedc18f0 100644 --- a/source/Handlebars/Compiler/Lexer/Parsers/BlockParamsParser.cs +++ b/source/Handlebars/Compiler/Lexer/Parsers/BlockParamsParser.cs @@ -23,7 +23,7 @@ private static string AccumulateWord(ExtendedStringReader reader) reader.Read(); - while (reader.Peek() != '|') + while (reader.Peek() != '|' && reader.Peek() != -1) { buffer.Append((char) reader.Read()); }