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

fix(dateparser): Throws on invalid date format string. #3691

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
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