Skip to content

Commit

Permalink
fix(isISO8601): disallow prepended and appended strings to RFC 3339 d…
Browse files Browse the repository at this point in the history
…ate-time (#1654)

Fixes #1653

Also adds corresponding test cases to ISO 8601 validator
  • Loading branch information
Joe MacMahon committed Apr 21, 2021
1 parent 24b3fd3 commit d1a9b6d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/isRFC3339.js
Expand Up @@ -19,7 +19,7 @@ const partialTime = new RegExp(`${timeHour.source}:${timeMinute.source}:${timeSe
const fullDate = new RegExp(`${dateFullYear.source}-${dateMonth.source}-${dateMDay.source}`);
const fullTime = new RegExp(`${partialTime.source}${timeOffset.source}`);

const rfc3339 = new RegExp(`${fullDate.source}[ tT]${fullTime.source}`);
const rfc3339 = new RegExp(`^${fullDate.source}[ tT]${fullTime.source}$`);

export default function isRFC3339(str) {
assertString(str);
Expand Down
4 changes: 4 additions & 0 deletions test/validators.js
Expand Up @@ -8925,6 +8925,8 @@ describe('Validators', () => {
'2010-02-18T16:23.33.600',
'2010-02-18T16,25:23:48,444',
'2010-13-1',
'nonsense2021-01-01T00:00:00Z',
'2021-01-01T00:00:00Znonsense',
];

it('should validate ISO 8601 dates', () => {
Expand Down Expand Up @@ -9107,6 +9109,8 @@ describe('Validators', () => {
'2009-05-00 14:39:22+0600',
'2009-00-1 14:39:22Z',
'2009-05-19T14:39:22',
'nonsense2021-01-01T00:00:00Z',
'2021-01-01T00:00:00Znonsense',
],
});
});
Expand Down

0 comments on commit d1a9b6d

Please sign in to comment.