From 29962f0fdb846cee3fa280daeb29bb00f300704a Mon Sep 17 00:00:00 2001 From: Anirudh Sanjeev Date: Tue, 19 Jul 2016 22:42:37 +0530 Subject: [PATCH] Handle back-ticks in expression --- src/parsers/expression.js | 2 +- test/unit/specs/parsers/expression_spec.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/parsers/expression.js b/src/parsers/expression.js index d80dec86c07..b0d962d6d38 100644 --- a/src/parsers/expression.js +++ b/src/parsers/expression.js @@ -23,7 +23,7 @@ const improperKeywordsRE = const wsRE = /\s/g const newlineRE = /\n/g -const saveRE = /[\{,]\s*[\w\$_]+\s*:|('(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`)|new |typeof |void /g +const saveRE = /[\{,]\s*[\w\$_]+\s*:|('(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\"']|\\.)*`|`(?:[^`\\]|\\.)*`)|new |typeof |void /g const restoreRE = /"(\d+)"/g const pathTestRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/ const identRE = /[^\w$\.](?:[A-Za-z_$][\w$]*)/g diff --git a/test/unit/specs/parsers/expression_spec.js b/test/unit/specs/parsers/expression_spec.js index 1de8f20d15f..c6981b334c5 100644 --- a/test/unit/specs/parsers/expression_spec.js +++ b/test/unit/specs/parsers/expression_spec.js @@ -67,6 +67,18 @@ var testCases = [ scope: {c: 32}, expected: { a: '35', b: 32 } }, + { + // Object with string values with back-quotes + exp: '[{"a":"he`llo"},{"b":"world"},{"c":55}]', + scope: {}, + expected: [{ 'a': 'he`llo'}, { 'b': 'world'}, { 'c': 55}] + }, + { + // Object with string values and back quotes (single quoted string) + exp: '[{\'a\':\'he`llo\'},{\'b\':\'world\'},{\'c\':55}]', + scope: {}, + expected: [{ 'a': 'he`llo'}, { 'b': 'world'}, { 'c': 55}] + }, { // dollar signs and underscore exp: "_a + ' ' + $b",