diff --git a/src/addons/MomentLocaleUtils.js b/src/addons/MomentLocaleUtils.js index 33af27fd0f..e50caabd7f 100644 --- a/src/addons/MomentLocaleUtils.js +++ b/src/addons/MomentLocaleUtils.js @@ -53,7 +53,7 @@ export function formatDate(date, format = 'L', locale = 'en') { } export function parseDate(str, format = 'L', locale = 'en') { - const m = moment(str, format, locale); + const m = moment(str, format, locale, true); if (m.isValid()) { return m.toDate(); } diff --git a/test/addons/MomentLocaleUtils.js b/test/addons/MomentLocaleUtils.js index 5850d05bb2..29e0cafa24 100644 --- a/test/addons/MomentLocaleUtils.js +++ b/test/addons/MomentLocaleUtils.js @@ -101,5 +101,9 @@ describe('MomentLocaleUtils', () => { const parsed = MomentLocaleUtils.parseDate('20 foo 2018', 'LL', 'it'); expect(parsed).toBeUndefined(); }); + it('return undefined if date does not match the format', () => { + const parsed = MomentLocaleUtils.parseDate('20/11/201', 'DD/MM/YYYY'); + expect(parsed).toBeUndefined(); + }); }); });