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

Commit

Permalink
fix(timepicker): prevent mixture of numbers and letters
Browse files Browse the repository at this point in the history
- More strictly parse the expressions for disallowing a mixture of numbers and letters

Closes #5201
Fixes #5085
  • Loading branch information
deeg authored and wesleycho committed Jan 11, 2016
1 parent 4b0e381 commit 9e9c6cf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/timepicker/test/timepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,6 @@ describe('timepicker directive', function() {
expect(getModelState()).toEqual([14, 9, 25]);
});


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

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

changeInputValueTo(el, 'pizza');
changeInputValueTo(el, '8a');
expect($rootScope.time).toBe(null);
expect(el.parent().hasClass('has-error')).toBe(true);
expect(element.hasClass('ng-invalid-time')).toBe(true);
Expand All @@ -1226,7 +1225,6 @@ describe('timepicker directive', function() {
expect(element.hasClass('ng-invalid-time')).toBe(false);
});


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

Expand Down
12 changes: 6 additions & 6 deletions src/timepicker/timepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ angular.module('ui.bootstrap.timepicker', [])
var hourStep = timepickerConfig.hourStep;
if ($attrs.hourStep) {
$scope.$parent.$watch($parse($attrs.hourStep), function(value) {
hourStep = parseInt(value, 10);
hourStep = +value;
});
}

var minuteStep = timepickerConfig.minuteStep;
if ($attrs.minuteStep) {
$scope.$parent.$watch($parse($attrs.minuteStep), function(value) {
minuteStep = parseInt(value, 10);
minuteStep = +value;
});
}

Expand Down Expand Up @@ -129,7 +129,7 @@ angular.module('ui.bootstrap.timepicker', [])
var secondStep = timepickerConfig.secondStep;
if ($attrs.secondStep) {
$scope.$parent.$watch($parse($attrs.secondStep), function(value) {
secondStep = parseInt(value, 10);
secondStep = +value;
});
}

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

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

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

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

Expand Down

0 comments on commit 9e9c6cf

Please sign in to comment.