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

fix(form): ignore properties in prototype chain in $error #10470

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ function forEach(obj, iterator, context) {
obj.forEach(iterator, context, obj);
} else {
for (key in obj) {
if (obj.hasOwnProperty(key)) {
if (hasOwnProperty.call(obj, key)) {
iterator.call(context, obj[key], key, obj);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ng/directive/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ function FormController(element, attrs, $scope, $animate, $interpolate) {
var parentForm = form.$$parentForm = element.parent().controller('form') || nullFormCtrl;

// init state
form.$error = {};
form.$$success = {};
form.$error = createMap();
form.$$success = createMap();
form.$pending = undefined;
form.$name = $interpolate(attrs.name || attrs.ngForm || '')($scope);
form.$dirty = false;
Expand Down
4 changes: 2 additions & 2 deletions src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -1744,8 +1744,8 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
this.$dirty = false;
this.$valid = true;
this.$invalid = false;
this.$error = {}; // keep invalid keys here
this.$$success = {}; // keep valid keys here
this.$error = createMap(); // keep invalid keys here
this.$$success = createMap(); // keep valid keys here
this.$pending = undefined; // keep pending keys here
this.$name = $interpolate($attr.name || '', false)($scope);

Expand Down
16 changes: 16 additions & 0 deletions test/ng/directive/inputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ describe('NgModelController', function() {
});


it('should ignore items in prototype chain when determining validity', inject(function($compile) {
dealoc(element);
Object.prototype.someProp = true;
element = $compile('<form name="form"><input type="text" ng-model="value" name="value"></form>')(scope);
var input = element.children().eq(0);
ctrl = input.controller('ngModel');
var form = element.controller('form');
scope.$digest();
expect(ctrl.$valid).toBe(true);
expect(element.children()).toBeValid();
expect(form.$valid).toBe(true);
expect(element).toBeValid();
delete Object.prototype.someProp;
}));


describe('setValidity', function() {

function expectOneError() {
Expand Down