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

Commit

Permalink
fix(dateparser): Throws on invalid date format string.
Browse files Browse the repository at this point in the history
Test unparsable date string is undefined.
  • Loading branch information
stevecavanagh committed Jan 18, 2016
1 parent 8a3c4b8 commit 24fe82e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/dateparser/dateparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ angular.module('ui.bootstrap.dateparser', [])
format[i] = '$';
}
format = format.join('');
var dupe = format.indexOf(data.key[0]);
if (dupe > -1 && !(format.slice(dupe, dupe + 3) === 'ss\\')) {
throw new Error('Invalid date format string.');
}

map.push({
index: index,
Expand Down
9 changes: 9 additions & 0 deletions src/dateparser/test/dateparser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,15 @@ describe('date parser', function() {
expect(dateParser.init).toHaveBeenCalled();
}));

it('should not parse if invalid format is specified', function () {
expect(function () {
dateParser.parse('20.12.20190', 'dd.MM.yyyyy');
}).toThrow(new Error('Invalid date format string.'));
});

it('should not parse if invalid value is specified', function () {
expect(dateParser.parse('20.12.20190', 'dd.MM.yyyy')).toBeUndefined();
});

describe('timezone functions', function() {
describe('toTimezone', function() {
Expand Down

0 comments on commit 24fe82e

Please sign in to comment.