Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 9e9c6cf

Browse files
deegwesleycho
authored andcommitted
fix(timepicker): prevent mixture of numbers and letters
- More strictly parse the expressions for disallowing a mixture of numbers and letters Closes #5201 Fixes #5085
1 parent 4b0e381 commit 9e9c6cf

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/timepicker/test/timepicker.spec.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,6 @@ describe('timepicker directive', function() {
11811181
expect(getModelState()).toEqual([14, 9, 25]);
11821182
});
11831183

1184-
11851184
it('updates seconds & pads on input change & pads on blur', function() {
11861185
var el = getSecondsInputEl();
11871186

@@ -1214,7 +1213,7 @@ describe('timepicker directive', function() {
12141213
it('clears model when input minutes is invalid & alerts the UI', function() {
12151214
var el = getMinutesInputEl();
12161215

1217-
changeInputValueTo(el, 'pizza');
1216+
changeInputValueTo(el, '8a');
12181217
expect($rootScope.time).toBe(null);
12191218
expect(el.parent().hasClass('has-error')).toBe(true);
12201219
expect(element.hasClass('ng-invalid-time')).toBe(true);
@@ -1226,7 +1225,6 @@ describe('timepicker directive', function() {
12261225
expect(element.hasClass('ng-invalid-time')).toBe(false);
12271226
});
12281227

1229-
12301228
it('clears model when input seconds is invalid & alerts the UI', function() {
12311229
var el = getSecondsInputEl();
12321230

src/timepicker/timepicker.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ angular.module('ui.bootstrap.timepicker', [])
5252
var hourStep = timepickerConfig.hourStep;
5353
if ($attrs.hourStep) {
5454
$scope.$parent.$watch($parse($attrs.hourStep), function(value) {
55-
hourStep = parseInt(value, 10);
55+
hourStep = +value;
5656
});
5757
}
5858

5959
var minuteStep = timepickerConfig.minuteStep;
6060
if ($attrs.minuteStep) {
6161
$scope.$parent.$watch($parse($attrs.minuteStep), function(value) {
62-
minuteStep = parseInt(value, 10);
62+
minuteStep = +value;
6363
});
6464
}
6565

@@ -129,7 +129,7 @@ angular.module('ui.bootstrap.timepicker', [])
129129
var secondStep = timepickerConfig.secondStep;
130130
if ($attrs.secondStep) {
131131
$scope.$parent.$watch($parse($attrs.secondStep), function(value) {
132-
secondStep = parseInt(value, 10);
132+
secondStep = +value;
133133
});
134134
}
135135

@@ -161,7 +161,7 @@ angular.module('ui.bootstrap.timepicker', [])
161161

162162
// Get $scope.hours in 24H mode if valid
163163
function getHoursFromTemplate() {
164-
var hours = parseInt($scope.hours, 10);
164+
var hours = +$scope.hours;
165165
var valid = $scope.showMeridian ? hours > 0 && hours < 13 :
166166
hours >= 0 && hours < 24;
167167
if (!valid) {
@@ -180,12 +180,12 @@ angular.module('ui.bootstrap.timepicker', [])
180180
}
181181

182182
function getMinutesFromTemplate() {
183-
var minutes = parseInt($scope.minutes, 10);
183+
var minutes = +$scope.minutes;
184184
return minutes >= 0 && minutes < 60 ? minutes : undefined;
185185
}
186186

187187
function getSecondsFromTemplate() {
188-
var seconds = parseInt($scope.seconds, 10);
188+
var seconds = +$scope.seconds;
189189
return seconds >= 0 && seconds < 60 ? seconds : undefined;
190190
}
191191

0 commit comments

Comments
 (0)