diff --git a/src/parseISO/index.js b/src/parseISO/index.js index f9c57f707c..54d57c10d3 100644 --- a/src/parseISO/index.js +++ b/src/parseISO/index.js @@ -154,6 +154,12 @@ function splitDateString(dateString) { var array = dateString.split(patterns.dateTimeDelimiter) var timeString + // The regex match should only return at maximum two array elements. + // [date], [time], or [date, time]. + if (array.length > 2) { + return dateStrings + } + if (/:/.test(array[0])) { dateStrings.date = null timeString = array[0] diff --git a/src/parseISO/test.js b/src/parseISO/test.js index e9618ad59b..3bed0ab105 100644 --- a/src/parseISO/test.js +++ b/src/parseISO/test.js @@ -286,6 +286,14 @@ describe('parseISO', () => { }) }) + describe('date', () => { + it('returns `Invalid Date` when it contains spaces after the date', () => { + const result = parseISO('2014-02-11 basketball') + assert(result instanceof Date) + assert(isNaN(result)) + }) + }) + describe('time', () => { it('parses 24:00 as midnight of the next day', () => { const result = parseISO('2014-02-11T24:00') @@ -321,6 +329,12 @@ describe('parseISO', () => { assert(result instanceof Date) assert(isNaN(result)) }) + + it('returns `Invalid Date` when it contains spaces after the time', () => { + const result = parseISO('2014-02-11T21:59:00 basketball') + assert(result instanceof Date) + assert(isNaN(result)) + }) }) describe('timezones', () => {