@@ -2962,39 +2962,221 @@ describe('parser', function() {
2962
2962
} ) . toThrow ( ) ;
2963
2963
} ) ;
2964
2964
2965
- it ( 'should prevent assigning in the context of a constructor' , function ( ) {
2965
+ they ( 'should prevent assigning in the context of the $prop constructor' , {
2966
+ Array : [ [ ] , '[]' ] ,
2967
+ Boolean : [ true , '(true)' ] ,
2968
+ Number : [ 1 , '(1)' ] ,
2969
+ String : [ 'string' , '"string"' ]
2970
+ } , function ( values ) {
2971
+ var thing = values [ 0 ] ;
2972
+ var expr = values [ 1 ] ;
2973
+ var constructorExpr = expr + '.constructor' ;
2974
+
2975
+ expect ( function ( ) {
2976
+ scope . $eval ( constructorExpr + '.join' ) ;
2977
+ } ) . not . toThrow ( ) ;
2966
2978
expect ( function ( ) {
2967
- scope . $eval ( "''.constructor.join" ) ;
2979
+ delete scope . foo ;
2980
+ scope . $eval ( 'foo = ' + constructorExpr + '.join' ) ;
2968
2981
} ) . not . toThrow ( ) ;
2969
2982
expect ( function ( ) {
2970
- scope . $eval ( "''.constructor.join = ''.constructor.join" ) ;
2983
+ scope . $eval ( constructorExpr + '.join = ""' ) ;
2984
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
2985
+ expect ( function ( ) {
2986
+ scope . $eval ( constructorExpr + '[0] = ""' ) ;
2987
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
2988
+ expect ( function ( ) {
2989
+ delete scope . foo ;
2990
+ scope . $eval ( 'foo = ' + constructorExpr + '; foo.join = ""' ) ;
2991
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
2992
+
2993
+ expect ( function ( ) {
2994
+ scope . foo = thing ;
2995
+ scope . $eval ( 'foo.constructor[0] = ""' ) ;
2996
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
2997
+ expect ( function ( ) {
2998
+ delete scope . foo ;
2999
+ scope . $eval ( 'foo.constructor[0] = ""' , { foo : thing } ) ;
3000
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3001
+ expect ( function ( ) {
3002
+ scope . foo = thing . constructor ;
3003
+ scope . $eval ( 'foo[0] = ""' ) ;
3004
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3005
+ expect ( function ( ) {
3006
+ delete scope . foo ;
3007
+ scope . $eval ( 'foo[0] = ""' , { foo : thing . constructor } ) ;
3008
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3009
+ } ) ;
3010
+
3011
+ they ( 'should prevent assigning in the context of the $prop constructor' , {
3012
+ // These might throw different error (e.g. isecobj, isecfn),
3013
+ // but still having them here for good measure
3014
+ Function : [ noop , '$eval' ] ,
3015
+ Object : [ { } , '{}' ]
3016
+ } , function ( values ) {
3017
+ var thing = values [ 0 ] ;
3018
+ var expr = values [ 1 ] ;
3019
+ var constructorExpr = expr + '.constructor' ;
3020
+
3021
+ expect ( function ( ) {
3022
+ scope . $eval ( constructorExpr + '.join' ) ;
3023
+ } ) . not . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3024
+ expect ( function ( ) {
3025
+ delete scope . foo ;
3026
+ scope . $eval ( 'foo = ' + constructorExpr + '.join' ) ;
3027
+ } ) . not . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3028
+ expect ( function ( ) {
3029
+ scope . $eval ( constructorExpr + '.join = ""' ) ;
2971
3030
} ) . toThrow ( ) ;
2972
3031
expect ( function ( ) {
2973
- scope . $eval ( "''.constructor [0] = ''" ) ;
3032
+ scope . $eval ( constructorExpr + ' [0] = ""' ) ;
2974
3033
} ) . toThrow ( ) ;
2975
3034
expect ( function ( ) {
2976
- scope . $eval ( "(0).constructor[0] = ''" ) ;
3035
+ delete scope . foo ;
3036
+ scope . $eval ( 'foo = ' + constructorExpr + '; foo.join = ""' ) ;
2977
3037
} ) . toThrow ( ) ;
3038
+
2978
3039
expect ( function ( ) {
2979
- scope . $eval ( "{}.constructor[0] = ''" ) ;
3040
+ scope . foo = thing ;
3041
+ scope . $eval ( 'foo.constructor[0] = ""' ) ;
2980
3042
} ) . toThrow ( ) ;
2981
- // foo.constructor is the object constructor.
2982
3043
expect ( function ( ) {
2983
- scope . $eval ( "foo.constructor[0] = ''" , { foo : { } } ) ;
3044
+ delete scope . foo ;
3045
+ scope . $eval ( 'foo.constructor[0] = ""' , { foo : thing } ) ;
2984
3046
} ) . toThrow ( ) ;
3047
+ expect ( function ( ) {
3048
+ scope . foo = thing . constructor ;
3049
+ scope . $eval ( 'foo[0] = ""' ) ;
3050
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3051
+ expect ( function ( ) {
3052
+ delete scope . foo ;
3053
+ scope . $eval ( 'foo[0] = ""' , { foo : thing . constructor } ) ;
3054
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3055
+ } ) ;
3056
+
3057
+ it ( 'should prevent assigning only in the context of an actual constructor' , function ( ) {
2985
3058
// foo.constructor is not a constructor.
2986
3059
expect ( function ( ) {
2987
- scope . $eval ( "foo.constructor[0] = ''" , { foo : { constructor : '' } } ) ;
3060
+ delete scope . foo ;
3061
+ scope . $eval ( 'foo.constructor[0] = ""' , { foo : { constructor : '' } } ) ;
3062
+ } ) . not . toThrow ( ) ;
3063
+
3064
+ expect ( function ( ) {
3065
+ scope . $eval ( '"a".constructor.prototype.charAt = [].join' ) ;
3066
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3067
+ expect ( function ( ) {
3068
+ scope . $eval ( '"a".constructor.prototype.charCodeAt = [].concat' ) ;
3069
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3070
+ } ) ;
3071
+
3072
+ they ( 'should prevent assigning in the context of the $prop constructor prototype' , {
3073
+ Array : [ [ ] , '[]' ] ,
3074
+ Boolean : [ true , '(true)' ] ,
3075
+ Number : [ 1 , '(1)' ] ,
3076
+ String : [ 'string' , '"string"' ]
3077
+ } , function ( values ) {
3078
+ var thing = values [ 0 ] ;
3079
+ var expr = values [ 1 ] ;
3080
+ var constructorExpr = expr + '.constructor' ;
3081
+ var prototypeExpr = constructorExpr + '.prototype' ;
3082
+
3083
+ expect ( function ( ) {
3084
+ scope . $eval ( prototypeExpr + '.boin' ) ;
3085
+ } ) . not . toThrow ( ) ;
3086
+ expect ( function ( ) {
3087
+ delete scope . foo ;
3088
+ scope . $eval ( 'foo = ' + prototypeExpr + '.boin' ) ;
2988
3089
} ) . not . toThrow ( ) ;
2989
3090
expect ( function ( ) {
2990
- scope . $eval ( "objConstructor = {}.constructor; objConstructor.join = ''" ) ;
3091
+ scope . $eval ( prototypeExpr + '.boin = ""' ) ;
3092
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3093
+ expect ( function ( ) {
3094
+ scope . $eval ( prototypeExpr + '[0] = ""' ) ;
3095
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3096
+ expect ( function ( ) {
3097
+ delete scope . foo ;
3098
+ scope . $eval ( 'foo = ' + constructorExpr + '; foo.prototype.boin = ""' ) ;
3099
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3100
+ expect ( function ( ) {
3101
+ delete scope . foo ;
3102
+ scope . $eval ( 'foo = ' + prototypeExpr + '; foo.boin = ""' ) ;
3103
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3104
+
3105
+ expect ( function ( ) {
3106
+ scope . foo = thing . constructor ;
3107
+ scope . $eval ( 'foo.prototype[0] = ""' ) ;
3108
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3109
+ expect ( function ( ) {
3110
+ delete scope . foo ;
3111
+ scope . $eval ( 'foo.prototype[0] = ""' , { foo : thing . constructor } ) ;
3112
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3113
+ expect ( function ( ) {
3114
+ scope . foo = thing . constructor . prototype ;
3115
+ scope . $eval ( 'foo[0] = ""' ) ;
3116
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3117
+ expect ( function ( ) {
3118
+ delete scope . foo ;
3119
+ scope . $eval ( 'foo[0] = ""' , { foo : thing . constructor . prototype } ) ;
3120
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3121
+ } ) ;
3122
+
3123
+ they ( 'should prevent assigning in the context of a constructor prototype' , {
3124
+ // These might throw different error (e.g. isecobj, isecfn),
3125
+ // but still having them here for good measure
3126
+ Function : [ noop , '$eval' ] ,
3127
+ Object : [ { } , '{}' ]
3128
+ } , function ( values ) {
3129
+ var thing = values [ 0 ] ;
3130
+ var expr = values [ 1 ] ;
3131
+ var constructorExpr = expr + '.constructor' ;
3132
+ var prototypeExpr = constructorExpr + '.prototype' ;
3133
+
3134
+ expect ( function ( ) {
3135
+ scope . $eval ( prototypeExpr + '.boin' ) ;
3136
+ } ) . not . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3137
+ expect ( function ( ) {
3138
+ delete scope . foo ;
3139
+ scope . $eval ( 'foo = ' + prototypeExpr + '.boin' ) ;
3140
+ } ) . not . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3141
+ expect ( function ( ) {
3142
+ scope . $eval ( prototypeExpr + '.boin = ""' ) ;
2991
3143
} ) . toThrow ( ) ;
2992
3144
expect ( function ( ) {
2993
- scope . $eval ( "'a'.constructor.prototype.charAt=[].join" ) ;
3145
+ scope . $eval ( prototypeExpr + '[0] = ""' ) ;
2994
3146
} ) . toThrow ( ) ;
2995
3147
expect ( function ( ) {
2996
- scope . $eval ( "'a'.constructor.prototype.charCodeAt=[].concat" ) ;
3148
+ delete scope . foo ;
3149
+ scope . $eval ( 'foo = ' + constructorExpr + '; foo.prototype.boin = ""' ) ;
2997
3150
} ) . toThrow ( ) ;
3151
+ expect ( function ( ) {
3152
+ delete scope . foo ;
3153
+ scope . $eval ( 'foo = ' + prototypeExpr + '; foo.boin = ""' ) ;
3154
+ } ) . toThrow ( ) ;
3155
+
3156
+ expect ( function ( ) {
3157
+ scope . foo = thing . constructor ;
3158
+ scope . $eval ( 'foo.prototype[0] = ""' ) ;
3159
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3160
+ expect ( function ( ) {
3161
+ delete scope . foo ;
3162
+ scope . $eval ( 'foo.prototype[0] = ""' , { foo : thing . constructor } ) ;
3163
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3164
+ expect ( function ( ) {
3165
+ scope . foo = thing . constructor . prototype ;
3166
+ scope . $eval ( 'foo[0] = ""' ) ;
3167
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3168
+ expect ( function ( ) {
3169
+ delete scope . foo ;
3170
+ scope . $eval ( 'foo[0] = ""' , { foo : thing . constructor . prototype } ) ;
3171
+ } ) . toThrowMinErr ( '$parse' , 'isecaf' ) ;
3172
+ } ) ;
3173
+
3174
+ it ( 'should prevent assigning only in the context of an actual prototype' , function ( ) {
3175
+ // foo.constructor.prototype is not a constructor prototype.
3176
+ expect ( function ( ) {
3177
+ delete scope . foo ;
3178
+ scope . $eval ( 'foo.constructor.prototype[0] = ""' , { foo : { constructor : { prototype : '' } } } ) ;
3179
+ } ) . not . toThrow ( ) ;
2998
3180
} ) ;
2999
3181
} ) ;
3000
3182
0 commit comments