From 4907f3854db49c4fae0cad9bc8d8ae192c1298d5 Mon Sep 17 00:00:00 2001 From: Fred Kleuver Date: Tue, 30 Oct 2018 03:42:52 +0100 Subject: [PATCH] fix(parser): throw on unterminated quote instead of infinite loop --- src/parser.js | 2 +- test/parser.spec.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/parser.js b/src/parser.js index 4149222a..256c1495 100644 --- a/src/parser.js +++ b/src/parser.js @@ -472,7 +472,7 @@ export class ParserImplementation { buffer.push(fromCharCode(unescaped)); marker = this.idx; - } else if (this.ch === /*EOF*/0) { + } else if (this.ch === /*EOF*/0 || this.idx >= this.len) { this.err('Unterminated quote'); } else { this.next(); diff --git a/test/parser.spec.js b/test/parser.spec.js index 5cf6ad4a..a6fc5421 100644 --- a/test/parser.spec.js +++ b/test/parser.spec.js @@ -661,6 +661,23 @@ describe('Parser', () => { }); describe('should not parse', () => { + describe('LiteralString with unterminated quote', () => { + const expressions = [ + '\'a', + '\'', + 'a\'', + '"a', + '"', + 'a"' + ]; + + for (const expr of expressions) { + it(expr, () => { + _verifyError(expr, 'Unterminated quote'); + }); + } + }); + describe('LiteralObject with computed property', () => { const expressions = [ '{ []: "foo" }',