Skip to content

Commit

Permalink
Fix parseISO not returning Invalid Date when there are spaces in pass…
Browse files Browse the repository at this point in the history
…ed string (#1791)
  • Loading branch information
imballinst committed Jul 17, 2020
1 parent d098e19 commit cff48aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/parseISO/index.js
Expand Up @@ -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]
Expand Down
14 changes: 14 additions & 0 deletions src/parseISO/test.js
Expand Up @@ -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')
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit cff48aa

Please sign in to comment.