Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit c207bff

Browse files
committed
test($parse): test more constructors against isecaf error
1 parent 10a6e1a commit c207bff

File tree

1 file changed

+95
-27
lines changed

1 file changed

+95
-27
lines changed

test/ng/parseSpec.js

Lines changed: 95 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2958,38 +2958,106 @@ describe('parser', function() {
29582958
});
29592959

29602960
it('should prevent assigning in the context of a constructor', function() {
2961-
expect(function() {
2962-
scope.$eval("''.constructor.join");
2963-
}).not.toThrow();
2964-
expect(function() {
2965-
scope.$eval("''.constructor.join = ''.constructor.join");
2966-
}).toThrow();
2967-
expect(function() {
2968-
scope.$eval("''.constructor[0] = ''");
2969-
}).toThrow();
2970-
expect(function() {
2971-
scope.$eval("(0).constructor[0] = ''");
2972-
}).toThrow();
2973-
expect(function() {
2974-
scope.$eval("{}.constructor[0] = ''");
2975-
}).toThrow();
2976-
// foo.constructor is the object constructor.
2977-
expect(function() {
2978-
scope.$eval("foo.constructor[0] = ''", {foo: {}});
2979-
}).toThrow();
2961+
forEach({
2962+
'(true)': true,
2963+
'(1)': 1,
2964+
'"string"': 'string',
2965+
'[]': []
2966+
}, function(thing, expr) {
2967+
var constructorExpr = expr + '.constructor';
2968+
2969+
expect(function() {
2970+
scope.$eval(constructorExpr + '.join');
2971+
}).not.toThrow();
2972+
expect(function() {
2973+
delete scope.foo;
2974+
scope.$eval('foo = ' + constructorExpr + '.join');
2975+
}).not.toThrow();
2976+
expect(function() {
2977+
scope.$eval(constructorExpr + '.join = ""');
2978+
}).toThrowMinErr('$parse', 'isecaf');
2979+
expect(function() {
2980+
scope.$eval(constructorExpr + '[0] = ""');
2981+
}).toThrowMinErr('$parse', 'isecaf');
2982+
expect(function() {
2983+
delete scope.foo;
2984+
scope.$eval('foo = ' + constructorExpr + '; foo.join = ""');
2985+
}).toThrowMinErr('$parse', 'isecaf');
2986+
2987+
expect(function() {
2988+
scope.foo = thing;
2989+
scope.$eval('foo.constructor[0] = ""');
2990+
}).toThrowMinErr('$parse', 'isecaf');
2991+
expect(function() {
2992+
delete scope.foo;
2993+
scope.$eval('foo.constructor[0] = ""', {foo: thing});
2994+
}).toThrowMinErr('$parse', 'isecaf');
2995+
expect(function() {
2996+
scope.foo = thing.constructor;
2997+
scope.$eval('foo[0] = ""');
2998+
}).toThrowMinErr('$parse', 'isecaf');
2999+
expect(function() {
3000+
delete scope.foo;
3001+
scope.$eval('foo[0] = ""', {foo: thing.constructor});
3002+
}).toThrowMinErr('$parse', 'isecaf');
3003+
});
3004+
3005+
// These might throw different error (e.g. isecobj, isecfn),
3006+
// but still having them here for good measure
3007+
forEach({
3008+
'{}': {},
3009+
'$eval': scope.$eval
3010+
}, function(thing, expr) {
3011+
var constructorExpr = expr + '.constructor';
3012+
3013+
expect(function() {
3014+
scope.$eval(constructorExpr + '.join');
3015+
}).not.toThrowMinErr('$parse', 'isecaf');
3016+
expect(function() {
3017+
delete scope.foo;
3018+
scope.$eval('foo = ' + constructorExpr + '.join');
3019+
}).not.toThrowMinErr('$parse', 'isecaf');
3020+
expect(function() {
3021+
scope.$eval(constructorExpr + '.join = ""');
3022+
}).toThrow();
3023+
expect(function() {
3024+
scope.$eval(constructorExpr + '[0] = ""');
3025+
}).toThrow();
3026+
expect(function() {
3027+
delete scope.foo;
3028+
scope.$eval('foo = ' + constructorExpr + '; foo.join = ""');
3029+
}).toThrow();
3030+
3031+
expect(function() {
3032+
scope.foo = thing;
3033+
scope.$eval('foo.constructor[0] = ""');
3034+
}).toThrow();
3035+
expect(function() {
3036+
delete scope.foo;
3037+
scope.$eval('foo.constructor[0] = ""', {foo: thing});
3038+
}).toThrow();
3039+
expect(function() {
3040+
scope.foo = thing.constructor;
3041+
scope.$eval('foo[0] = ""');
3042+
}).toThrowMinErr('$parse', 'isecaf');
3043+
expect(function() {
3044+
delete scope.foo;
3045+
scope.$eval('foo[0] = ""', {foo: thing.constructor});
3046+
}).toThrowMinErr('$parse', 'isecaf');
3047+
});
3048+
29803049
// foo.constructor is not a constructor.
29813050
expect(function() {
2982-
scope.$eval("foo.constructor[0] = ''", {foo: {constructor: ''}});
3051+
delete scope.foo;
3052+
scope.$eval('foo.constructor[0] = ""', {foo: {constructor: ''}});
29833053
}).not.toThrow();
3054+
29843055
expect(function() {
2985-
scope.$eval("objConstructor = {}.constructor; objConstructor.join = ''");
2986-
}).toThrow();
2987-
expect(function() {
2988-
scope.$eval("'a'.constructor.prototype.charAt=[].join");
2989-
}).toThrow();
3056+
scope.$eval('"a".constructor.prototype.charAt = [].join');
3057+
}).toThrowMinErr('$parse', 'isecaf');
29903058
expect(function() {
2991-
scope.$eval("'a'.constructor.prototype.charCodeAt=[].concat");
2992-
}).toThrow();
3059+
scope.$eval('"a".constructor.prototype.charCodeAt = [].concat');
3060+
}).toThrowMinErr('$parse', 'isecaf');
29933061
});
29943062
});
29953063

0 commit comments

Comments
 (0)