Skip to content

Commit 4d4059b

Browse files
committed
improve expression parser literal check
1 parent 00dc106 commit 4d4059b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Diff for: src/parsers/expression.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const saveRE = /[\{,]\s*[\w\$_]+\s*:|('(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^
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
30-
const booleanLiteralRE = /^(?:true|false)$/
30+
const literalValueRE = /^(?:true|false|null|undefined|Infinity|NaN)$/
3131

3232
function noop () {}
3333

@@ -222,8 +222,8 @@ export function parseExpression (exp, needSet) {
222222

223223
export function isSimplePath (exp) {
224224
return pathTestRE.test(exp) &&
225-
// don't treat true/false as paths
226-
!booleanLiteralRE.test(exp) &&
225+
// don't treat literal values as paths
226+
!literalValueRE.test(exp) &&
227227
// Math constants e.g. Math.PI, Math.E etc.
228228
exp.slice(0, 5) !== 'Math.'
229229
}

Diff for: test/unit/specs/parsers/expression_spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ var testCases = [
224224
expected: null,
225225
paths: []
226226
},
227+
{
228+
exp: 'undefined',
229+
scope: { undefined: 1 },
230+
expected: undefined,
231+
paths: []
232+
},
227233
{
228234
// Date global
229235
exp: 'Date.now() > new Date("2000-01-01")',

0 commit comments

Comments
 (0)