Skip to content

Commit bfdab5c

Browse files
authored
fix: more strict delimiter in REGEX_PARSE (#1555)
1 parent 8e32164 commit bfdab5c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/constant.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ export const FORMAT_DEFAULT = 'YYYY-MM-DDTHH:mm:ssZ'
2626
export const INVALID_DATE_STRING = 'Invalid Date'
2727

2828
// regex
29-
export const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/
29+
export const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/
3030
export const REGEX_FORMAT = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g

test/parse.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,12 @@ describe('REGEX_PARSE', () => {
201201
expect(dayjs(date).valueOf()).toBe(moment(date).valueOf())
202202
expect(d).toBe(null)
203203
})
204+
205+
// dots should not be matched, and fallback to Date
206+
it('2021.01.03', () => {
207+
const date = '2021.01.03'
208+
const d = date.match(REGEX_PARSE)
209+
expect(dayjs(date).valueOf()).toBe(moment(date).valueOf())
210+
expect(d).toBe(null)
211+
})
204212
})

0 commit comments

Comments
 (0)