diff --git a/src/dateparser/dateparser.js b/src/dateparser/dateparser.js index fa3004533b..72b5eebeb5 100644 --- a/src/dateparser/dateparser.js +++ b/src/dateparser/dateparser.js @@ -95,6 +95,10 @@ angular.module('ui.bootstrap.dateparser', []) format[i] = '$'; } format = format.join(''); + var dupe=format.indexOf(code[0]); + if (dupe>-1){ + throw new Error('Invalid date format string.'); + } map.push({ index: index, apply: data.apply }); } diff --git a/src/dateparser/test/dateparser.spec.js b/src/dateparser/test/dateparser.spec.js index 7ed6bb0e58..13f0629655 100644 --- a/src/dateparser/test/dateparser.spec.js +++ b/src/dateparser/test/dateparser.spec.js @@ -173,4 +173,12 @@ describe('date parser', function () { it('should not parse if no format is specified', function() { expect(dateParser.parse('21.08.1951', '')).toBe('21.08.1951'); }); + + 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(); + }); });