File tree Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ var restoreRE = /"(\d+)"/g
21
21
var pathTestRE = / ^ [ A - Z a - z _ $ ] [ \w $ ] * ( \. [ A - Z a - z _ $ ] [ \w $ ] * | \[ ' .* ?' \] | \[ " .* ?" \] | \[ \d + \] ) * $ /
22
22
var pathReplaceRE = / [ ^ \w $ \. ] ( [ A - Z a - z _ $ ] [ \w $ ] * ( \. [ A - Z a - z _ $ ] [ \w $ ] * | \[ ' .* ?' \] | \[ " .* ?" \] ) * ) / g
23
23
var keywordsRE = new RegExp ( '^(' + keywords . replace ( / , / g, '\\b|' ) + '\\b)' )
24
+ var booleanLiteralRE = / ^ ( t r u e | f a l s e ) $ /
24
25
25
26
/**
26
27
* Save / Rewrite / Restore
@@ -225,10 +226,14 @@ exports.parse = function (exp, needSet) {
225
226
// we do a simple path check to optimize for them.
226
227
// the check fails valid paths with unusal whitespaces,
227
228
// but that's too rare and we don't care.
228
- // also skip paths that start with global "Math"
229
- var res = pathTestRE . test ( exp ) && exp . slice ( 0 , 5 ) !== 'Math.'
230
- ? compilePathFns ( exp )
231
- : compileExpFns ( exp , needSet )
229
+ // also skip boolean literals and paths that start with
230
+ // global "Math"
231
+ var res =
232
+ pathTestRE . test ( exp ) &&
233
+ ! booleanLiteralRE . test ( exp ) &&
234
+ exp . slice ( 0 , 5 ) !== 'Math.'
235
+ ? compilePathFns ( exp )
236
+ : compileExpFns ( exp , needSet )
232
237
expressionCache . put ( exp , res )
233
238
return res
234
239
}
Original file line number Diff line number Diff line change @@ -188,13 +188,22 @@ var testCases = [
188
188
} ,
189
189
expected : Math . sin ( 1 ) ,
190
190
paths : [ 'a' ]
191
+ } ,
192
+ {
193
+ // boolean literal
194
+ exp : 'true' ,
195
+ scope : {
196
+ true : false
197
+ } ,
198
+ expected : true ,
199
+ paths : [ ]
191
200
}
192
201
]
193
202
194
203
describe ( 'Expression Parser' , function ( ) {
195
-
196
- it ( 'parse getter' , function ( ) {
197
- testCases . forEach ( function assertExp ( testCase ) {
204
+
205
+ testCases . forEach ( function ( testCase ) {
206
+ it ( 'parse getter: ' + testCase . exp , function ( ) {
198
207
var res = expParser . parse ( testCase . exp , true )
199
208
expect ( res . get ( testCase . scope ) ) . toEqual ( testCase . expected )
200
209
} )
You can’t perform that action at this time.
0 commit comments