From 7d7e3c0ac0a741131af608b026ebbae61dd3910d Mon Sep 17 00:00:00 2001 From: Anthony Halliday Date: Tue, 13 Dec 2022 12:06:06 +0000 Subject: [PATCH 1/2] Exit loop when reaching the reader end --- source/Handlebars/Compiler/Lexer/Parsers/BlockParamsParser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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()); } From 8dc42f601ea4a1abce34352ead3f03cb5c63cb80 Mon Sep 17 00:00:00 2001 From: Anthony Halliday Date: Tue, 13 Dec 2022 12:07:37 +0000 Subject: [PATCH 2/2] Added unit test for issue 535 --- source/Handlebars.Test/IssueTests.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) 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