Skip to content

Commit

Permalink
Merge pull request mozilla#23 from rehandalal/fix-string-parsing
Browse files Browse the repository at this point in the history
Fix issue with escaped quotes at the end of string
  • Loading branch information
rehandalal authored Mar 27, 2019
2 parents 3c1cd5e + 4ba03ed commit 3d09092
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ var numericRegex = /^-?(?:(?:[0-9]*\.[0-9]+)|[0-9]+)$/,
escEscRegex = /\\\\/,
preOpRegexElems = [
// Strings
"'(?:(?:\\\\')?[^'])*'",
'"(?:(?:\\\\")?[^"])*"',
"'(?:(?:\\\\')|[^'])*'",
'"(?:(?:\\\\")|[^"])*"',
// Whitespace
"\\s+",
// Booleans
Expand Down
12 changes: 12 additions & 0 deletions test/Lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3d09092

Please sign in to comment.