From 7321efa76e81a19cf6578cd544c4e4ac6783eada Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Tue, 9 Jan 2018 14:26:19 -0500 Subject: [PATCH] Out of memory on missing quote fixes #31 --- lexer/lexer.go | 2 +- plush_test.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lexer/lexer.go b/lexer/lexer.go index 5c33cde..b900f6f 100644 --- a/lexer/lexer.go +++ b/lexer/lexer.go @@ -250,7 +250,7 @@ func (l *Lexer) readNumber() string { func (l *Lexer) readString() string { position := l.position + 1 - for { + for l.ch != 0 { l.readChar() // check for quote escapes if l.ch == '\\' && l.peekChar() == '"' { diff --git a/plush_test.go b/plush_test.go index 0ab8f01..9c9356f 100644 --- a/plush_test.go +++ b/plush_test.go @@ -448,6 +448,15 @@ func Test_LineNumberErrors_InsideForLoop(t *testing.T) { r.Contains(err.Error(), "line 3:") } +func Test_MissingQuote(t *testing.T) { + r := require.New(t) + input := `<%= foo("asdf) %>` + ctx := NewContext() + ctx.Set("foo", func(string) {}) + _, err := Render(input, ctx) + r.Error(err) +} + func Test_RunScript(t *testing.T) { r := require.New(t) bb := &bytes.Buffer{}