From 4ba03edcaddf602fe12ee23b37b6d0926447df0e Mon Sep 17 00:00:00 2001 From: Rehan Dalal Date: Tue, 26 Mar 2019 06:47:50 -0400 Subject: [PATCH] Fix issue with escaped quotes at the end of string --- lib/Lexer.js | 4 ++-- test/Lexer.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/Lexer.js b/lib/Lexer.js index c2e8bc9..b683c9a 100644 --- a/lib/Lexer.js +++ b/lib/Lexer.js @@ -8,8 +8,8 @@ var numericRegex = /^-?(?:(?:[0-9]*\.[0-9]+)|[0-9]+)$/, escEscRegex = /\\\\/, preOpRegexElems = [ // Strings - "'(?:(?:\\\\')?[^'])*'", - '"(?:(?:\\\\")?[^"])*"', + "'(?:(?:\\\\')|[^'])*'", + '"(?:(?:\\\\")|[^"])*"', // Whitespace "\\s+", // Booleans diff --git a/test/Lexer.js b/test/Lexer.js index 3c87c96..a039f31 100644 --- a/test/Lexer.js +++ b/test/Lexer.js @@ -34,12 +34,24 @@ describe("Lexer", function() { elems.should.have.length(1); elems[0].should.equal(str); }); + it("should support escaping double-quotes at end of double-quote strings", function() { + var str = '"\\""', + elems = inst.getElements(str); + elems.should.have.length(1); + elems[0].should.equal(str); + }); it("should support escaping single-quotes", function() { var str = "'f\\'oo'", elems = inst.getElements(str); elems.should.have.length(1); elems[0].should.equal(str); }); + it("should support escaping single-quotes at end of single-quote strings", function() { + var str = "'\\''", + elems = inst.getElements(str); + elems.should.have.length(1); + elems[0].should.equal(str); + }); it("should count an identifier as one element", function() { var str = "alpha12345", elems = inst.getElements(str);