aboutsummaryrefslogtreecommitdiffstats
path: root/test/auto/injectorSpec.js
diff options
context:
space:
mode:
authorPeter Bacon Darwin2013-10-05 10:49:09 +0100
committerVojta Jina2013-10-07 09:01:13 -0700
commit7a586e5c19f3d1ecc3fefef084ce992072ee7f60 (patch)
tree2690c915adb20d92a065d9ad9d7438766d4620f8 /test/auto/injectorSpec.js
parentfb99f542060d3959d273634c90889788861b5c05 (diff)
downloadangular.js-7a586e5c19f3d1ecc3fefef084ce992072ee7f60.tar.bz2
fix(*): protect calls to hasOwnProperty in public API
Objects received from outside AngularJS may have had their `hasOwnProperty` method overridden with something else. In cases where we can do this without incurring a performance penalty we call directly on Object.prototype.hasOwnProperty to ensure that we use the correct method. Also, we have some internal hash objects, where the keys for the map are provided from outside AngularJS. In such cases we either prevent `hasOwnProperty` from being used as a key or provide some other way of preventing our objects from having their `hasOwnProperty` overridden. BREAKING CHANGE: Inputs with name equal to "hasOwnProperty" are not allowed inside form or ngForm directives. Before, inputs whose name was "hasOwnProperty" were quietly ignored and not added to the scope. Now a badname exception is thrown. Using "hasOwnProperty" for an input name would be very unusual and bad practice. Either do not include such an input in a `form` or `ngForm` directive or change the name of the input. Closes #3331
Diffstat (limited to 'test/auto/injectorSpec.js')
-rw-r--r--test/auto/injectorSpec.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/auto/injectorSpec.js b/test/auto/injectorSpec.js
index f010fc91..5c186cf1 100644
--- a/test/auto/injectorSpec.js
+++ b/test/auto/injectorSpec.js
@@ -295,6 +295,24 @@ describe('injector', function() {
});
describe('$provide', function() {
+
+ it('should throw an exception if we try to register a service called "hasOwnProperty"', function() {
+ createInjector([function($provide) {
+ expect(function() {
+ $provide.provider('hasOwnProperty', function() { });
+ }).toThrowMinErr('ng', 'badname');
+ }]);
+ });
+
+ it('should throw an exception if we try to register a constant called "hasOwnProperty"', function() {
+ createInjector([function($provide) {
+ expect(function() {
+ $provide.constant('hasOwnProperty', {});
+ }).toThrowMinErr('ng', 'badname');
+ }]);
+ });
+
+
describe('constant', function() {
it('should create configuration injectable constants', function() {
var log = [];