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

fix(input[radio]): use strict comparison when evaluating checked-ness #15288

Merged
merged 1 commit into from
Nov 8, 2016
Merged
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
4 changes: 1 addition & 3 deletions src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -1761,9 +1761,7 @@ function radioInputType(scope, element, attr, ctrl) {
if (doTrim) {
value = trim(value);
}
// Strict comparison would cause a BC
// eslint-disable-next-line eqeqeq
element[0].checked = (value == ctrl.$viewValue);
element[0].checked = (value === ctrl.$viewValue);
};

attr.$observe('value', ctrl.$render);
Expand Down
18 changes: 14 additions & 4 deletions test/ng/directive/inputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3867,17 +3867,15 @@ describe('input', function() {
expect($rootScope.color).toBe('blue');
});


// We generally use strict comparison. This tests behavior we cannot change without a BC
it('should use non-strict comparison the evaluate checked-ness', function() {
it('should treat the value as a string when evaluating checked-ness', function() {
var inputElm = helper.compileInput(
'<input type="radio" ng-model="model" value="0" />');

$rootScope.$apply('model = \'0\'');
expect(inputElm[0].checked).toBe(true);

$rootScope.$apply('model = 0');
expect(inputElm[0].checked).toBe(true);
expect(inputElm[0].checked).toBe(false);
});


Expand Down Expand Up @@ -4131,6 +4129,18 @@ describe('input', function() {
});


it('should use strict comparison between model and value', function() {
$rootScope.selected = false;
var inputElm = helper.compileInput('<input type="radio" ng-model="selected" ng-value="false">' +
'<input type="radio" ng-model="selected" ng-value="\'\'">' +
'<input type="radio" ng-model="selected" ng-value="0">');

expect(inputElm[0].checked).toBe(true);
expect(inputElm[1].checked).toBe(false);
expect(inputElm[2].checked).toBe(false);
});


it('should watch the expression', function() {
var inputElm = helper.compileInput('<input type="radio" ng-model="selected" ng-value="value">');

Expand Down