@@ -29,21 +29,31 @@ var promiseWarning;
2929
3030
3131function ensureSafeMemberName ( name , fullExpression ) {
32+ if ( name === "__defineGetter__" || name === "__defineSetter__"
33+ || name === "__lookupGetter__" || name === "__lookupSetter__"
34+ || name === "__proto__" ) {
35+ throw $parseMinErr ( 'isecfld' ,
36+ 'Attempting to access a disallowed field in Angular expressions! '
37+ + 'Expression: {0}' , fullExpression ) ;
38+ }
39+ return name ;
40+ }
41+
42+ function getStringValue ( name , fullExpression ) {
3243 // From the JavaScript docs:
3344 // Property names must be strings. This means that non-string objects cannot be used
3445 // as keys in an object. Any non-string object, including a number, is typecasted
3546 // into a string via the toString method.
3647 //
3748 // So, to ensure that we are checking the same `name` that JavaScript would use,
38- // we cast it to a string, if possible
39- name = ( isObject ( name ) && name . toString ) ? name . toString ( ) : name ;
40-
41- if ( name === "__defineGetter__" || name === "__defineSetter__"
42- || name === "__lookupGetter__" || name === "__lookupSetter__"
43- || name === "__proto__" ) {
44- throw $parseMinErr ( 'isecfld' ,
45- 'Attempting to access a disallowed field in Angular expressions! '
46- + 'Expression: {0}' , fullExpression ) ;
49+ // we cast it to a string, if possible.
50+ // Doing `name + ''` can cause a repl error if the result to `toString` is not a string,
51+ // this is, this will handle objects that misbehave.
52+ name = name + '' ;
53+ if ( ! isString ( name ) ) {
54+ throw $parseMinErr ( 'iseccst' ,
55+ 'Cannot convert object to primitive value! '
56+ + 'Expression: {0}' , fullExpression ) ;
4757 }
4858 return name ;
4959}
@@ -722,7 +732,7 @@ Parser.prototype = {
722732
723733 return extend ( function ( self , locals ) {
724734 var o = obj ( self , locals ) ,
725- i = indexFn ( self , locals ) ,
735+ i = getStringValue ( indexFn ( self , locals ) , parser . text ) ,
726736 v , p ;
727737
728738 ensureSafeMemberName ( i , parser . text ) ;
@@ -739,7 +749,7 @@ Parser.prototype = {
739749 return v ;
740750 } , {
741751 assign : function ( self , value , locals ) {
742- var key = ensureSafeMemberName ( indexFn ( self , locals ) , parser . text ) ;
752+ var key = ensureSafeMemberName ( getStringValue ( indexFn ( self , locals ) , parser . text ) , parser . text ) ;
743753 // prevent overwriting of Function.constructor which would break ensureSafeObject check
744754 var o = ensureSafeObject ( obj ( self , locals ) , parser . text ) ;
745755 if ( ! o ) obj . assign ( self , o = { } ) ;
0 commit comments