From a1c2857ba42aed5551e51baac0804d14ac9939ab Mon Sep 17 00:00:00 2001 From: Ajinkya Tejankar Date: Fri, 29 Jan 2016 21:20:45 +0530 Subject: [PATCH] bug(parsing): Check quoteChar before leaving 'QUOTE' --- lib/parser.js | 4 ++-- test/parser.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/parser.js b/lib/parser.js index 0e8aa0d..f494f66 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -7,7 +7,7 @@ rules.set(/['"`]/, (char, state) => { state.name = 'QUOTE'; state.quoteChar = char; return true; - } else if (state.name === 'QUOTE') { + } else if (state.name === 'QUOTE' && char === state.quoteChar) { state.name = 'START'; state.quoteChar = undefined; return true; @@ -31,7 +31,7 @@ rules.set(/\//, (char, state) => { } else if (state.name === 'COMMENT_ML_END1') { state.name = 'START'; return true; - } else if (state.name === 'QUOTE') { + } else if (state.name === 'QUOTE' && char === state.quoteChar) { state.name = 'START'; state.quoteChar = undefined; return true; diff --git a/test/parser.js b/test/parser.js index 370132d..be868ae 100644 --- a/test/parser.js +++ b/test/parser.js @@ -119,7 +119,7 @@ describe('parser', () => { it('should handle regex literals in actions', () => { let input = ` **/dep/*.!{html.js} { - let regex = /random\\/art\\{bram\\}/g; + let regex = /'random\\/"art"\\{bram\\}'/g; pf($key); pf($val); } @@ -140,8 +140,8 @@ describe('parser', () => { it('should handle quote literals literals in actions', () => { let input = ` **/dep/*.!{html.js} { - let quote1 = 'random { } art'; - let quote2 = "random { } art" + let quote1 = 'random { } "\` art/'; + let quote2 = "random { } '\` art" let quote3 = \`random { } art\`; pf($key); pf($val);