Skip to content

Commit b8f730c

Browse files
skyronicyyx990803
authored andcommitted
Handle back-ticks in expression (vuejs#3292)
1 parent c289a7e commit b8f730c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/parsers/expression.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const improperKeywordsRE =
2323

2424
const wsRE = /\s/g
2525
const newlineRE = /\n/g
26-
const saveRE = /[\{,]\s*[\w\$_]+\s*:|('(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`)|new |typeof |void /g
26+
const saveRE = /[\{,]\s*[\w\$_]+\s*:|('(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\"']|\\.)*`|`(?:[^`\\]|\\.)*`)|new |typeof |void /g
2727
const restoreRE = /"(\d+)"/g
2828
const pathTestRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/
2929
const identRE = /[^\w$\.](?:[A-Za-z_$][\w$]*)/g

test/unit/specs/parsers/expression_spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ var testCases = [
6767
scope: {c: 32},
6868
expected: { a: '35', b: 32 }
6969
},
70+
{
71+
// Object with string values with back-quotes
72+
exp: '[{"a":"he`llo"},{"b":"world"},{"c":55}]',
73+
scope: {},
74+
expected: [{ 'a': 'he`llo'}, { 'b': 'world'}, { 'c': 55}]
75+
},
76+
{
77+
// Object with string values and back quotes (single quoted string)
78+
exp: '[{\'a\':\'he`llo\'},{\'b\':\'world\'},{\'c\':55}]',
79+
scope: {},
80+
expected: [{ 'a': 'he`llo'}, { 'b': 'world'}, { 'c': 55}]
81+
},
7082
{
7183
// dollar signs and underscore
7284
exp: "_a + ' ' + $b",

0 commit comments

Comments
 (0)