@@ -3,24 +3,29 @@ var Path = require('./path')
33var Cache = require ( '../cache' )
44var expressionCache = new Cache ( 1000 )
55
6- var keywords =
7- 'Math,Date,break,case,catch,continue,debugger,default,' +
8- 'delete,do,else,false,finally,for,function,if,in,' +
9- 'instanceof,new,null,return,switch,this,throw,true,try,' +
10- 'typeof,var,void,while,with,undefined,abstract,boolean,' +
11- 'byte,char,class,const,double,enum,export,extends,' +
12- 'final,float,goto,implements,import,int,interface,long,' +
13- 'native,package,private,protected,public,short,static,' +
14- 'super,synchronized,throws,transient,volatile,' +
15- 'arguments,let,yield'
6+ var allowedKeywords =
7+ 'Math,Date,this,true,false,null,undefined,Infinity,NaN,' +
8+ 'isNaN,isFinite,decodeURI,decodeURIComponent,encodeURI,' +
9+ 'encodeURIComponent,parseInt,parseFloat'
10+ var allowedKeywordsRE =
11+ new RegExp ( '^(' + allowedKeywords . replace ( / , / g, '\\b|' ) + '\\b)' )
12+
13+ // keywords that don't make sense inside expressions
14+ var imporperKeywords =
15+ 'break,case,class,catch,const,continue,debugger,default,' +
16+ 'delete,do,else,export,extends,finally,for,function,if,' +
17+ 'import,in,instanceof,let,return,super,switch,throw,try,' +
18+ 'var,while,with,yield,enum,await,implements,package,' +
19+ 'proctected,static,interface,private,public'
20+ var imporoperKeywordsRE =
21+ new RegExp ( '^(' + imporperKeywords . replace ( / , / g, '\\b|' ) + '\\b)' )
1622
1723var wsRE = / \s / g
1824var newlineRE = / \n / g
19- var saveRE = / [ \{ , ] \s * [ \w \$ _ ] + \s * : | ( ' [ ^ ' ] * ' | " [ ^ " ] * " ) | n e w / g
25+ var saveRE = / [ \{ , ] \s * [ \w \$ _ ] + \s * : | ( ' [ ^ ' ] * ' | " [ ^ " ] * " ) | n e w | t y p e o f | v o i d / g
2026var restoreRE = / " ( \d + ) " / g
2127var pathTestRE = / ^ [ A - Z a - z _ $ ] [ \w $ ] * ( \. [ A - Z a - z _ $ ] [ \w $ ] * | \[ ' .* ?' \] | \[ " .* ?" \] | \[ \d + \] ) * $ /
2228var pathReplaceRE = / [ ^ \w $ \. ] ( [ A - Z a - z _ $ ] [ \w $ ] * ( \. [ A - Z a - z _ $ ] [ \w $ ] * | \[ ' .* ?' \] | \[ " .* ?" \] ) * ) / g
23- var keywordsRE = new RegExp ( '^(' + keywords . replace ( / , / g, '\\b|' ) + '\\b)' )
2429var booleanLiteralRE = / ^ ( t r u e | f a l s e ) $ /
2530
2631/**
@@ -68,7 +73,7 @@ function save (str, isString) {
6873function rewrite ( raw ) {
6974 var c = raw . charAt ( 0 )
7075 var path = raw . slice ( 1 )
71- if ( keywordsRE . test ( path ) ) {
76+ if ( allowedKeywordsRE . test ( path ) ) {
7277 return raw
7378 } else {
7479 path = path . indexOf ( '"' ) > - 1
@@ -100,6 +105,12 @@ function restore (str, i) {
100105 */
101106
102107function compileExpFns ( exp , needSet ) {
108+ if ( imporoperKeywordsRE . test ( exp ) ) {
109+ _ . warn (
110+ 'Avoid using reserved keywords in expression: '
111+ + exp
112+ )
113+ }
103114 // reset state
104115 saved . length = 0
105116 // save strings and object literal keys
@@ -230,7 +241,9 @@ exports.parse = function (exp, needSet) {
230241 // global "Math"
231242 var res =
232243 pathTestRE . test ( exp ) &&
244+ // don't treat true/false as paths
233245 ! booleanLiteralRE . test ( exp ) &&
246+ // Math constants e.g. Math.PI, Math.E etc.
234247 exp . slice ( 0 , 5 ) !== 'Math.'
235248 ? compilePathFns ( exp )
236249 : compileExpFns ( exp , needSet )
0 commit comments