Skip to content

Commit c95ebdf

Browse files
committed
fix(isISO8601): reject whitespace other than space as date-time separator
1 parent a79ff98 commit c95ebdf

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/lib/isISO8601.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import assertString from './util/assertString';
22

33
/* eslint-disable max-len */
44
// from http://goo.gl/0ejHHW
5-
const iso8601 = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W(0[1-9]|[1-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[0-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
5+
const iso8601 = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W(0[1-9]|[1-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[0-6])))([T ]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
66
// same as above, except with a strict 'T' separator between date and time
77
const iso8601StrictSeparator = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W(0[1-9]|[1-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[0-6])))([T]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
88
/* eslint-enable max-len */

test/validators.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12420,6 +12420,22 @@ describe('Validators', () => {
1242012420
});
1242112421
});
1242212422

12423+
it('should validate ISO 8601 dates, rejecting whitespace other than a space as the date-time separator', () => {
12424+
test({
12425+
validator: 'isISO8601',
12426+
valid: [
12427+
'2009-05-19T14:39:22',
12428+
'2009-05-19 14:39:22',
12429+
],
12430+
invalid: [
12431+
'2009-05-19\t14:39:22',
12432+
'2009-05-19\n14:39:22',
12433+
'2009-05-19\f14:39:22',
12434+
'2009-05-19\v14:39:22',
12435+
],
12436+
});
12437+
});
12438+
1242312439
it('should validate ISO 8601 dates, with strict = true (regression)', () => {
1242412440
test({
1242512441
validator: 'isISO8601',

0 commit comments

Comments
 (0)