fix(isISO8601): reject non-space whitespace as the date-time separator - #2874
Open
yfwmaniish wants to merge 1 commit into
Open
fix(isISO8601): reject non-space whitespace as the date-time separator#2874yfwmaniish wants to merge 1 commit into
yfwmaniish wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2874 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 114 114
Lines 2599 2599
Branches 658 658
=========================================
Hits 2599 2599 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes isISO8601 default validation in src/lib/isISO8601.js to reject non-space whitespace characters (e.g., tab/newline) as the date-time separator, aligning behavior with ISO 8601 / RFC 3339 expectations and addressing #2861.
Changes:
- Tighten the default ISO 8601 regex separator from
[T\\s]to[T ](allow onlyTor a literal space). - Add regression test cases ensuring tab/newline/form-feed/vertical-tab/non-breaking-space separators are rejected.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/lib/isISO8601.js | Updates the default ISO 8601 regex to disallow non-space whitespace as the date-time separator. |
| test/validators.test.js | Extends invalidISO8601 test inputs to cover non-space whitespace separators (including NBSP). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| '2009-01-01\n00:00:00', | ||
| '2009-01-01\f00:00:00', | ||
| '2009-01-01\v00:00:00', | ||
| '2009-01-01 00:00:00', |
The default (non-strictSeparator) regex used [T\s] for the date-time separator. \s matches tab, newline, form feed, vertical tab, and non-breaking space in addition to a plain space, so all of them were accepted between the date and time parts. ISO 8601 permits only 'T'; RFC 3339 SS5.6 additionally allows a plain space by convention, which is presumably why the class was there, but neither spec permits the rest of \s -- a newline in particular lets a two-line input pass a single-value check. Change [T\s] to [T ] so only 'T' or a literal space separates the date and time. strictSeparator was already unaffected (it only ever allowed [T]). Fixes validatorjs#2861
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2861.
What
The default (non-
strictSeparator)iso8601regex used[T\s]for the date-time separator.\smatches tab, newline, form feed, vertical tab, and non-breaking space in addition to a plain space, so all of them were accepted between the date and time parts:ISO 8601 itself permits only
T. RFC 3339 §5.6 additionally allows a plain space by convention, which is presumably why the character class was there in the first place — but neither spec permits the rest of\s. A newline in particular is worth rejecting on its own: it lets a two-line input pass what's meant to be a single-value check.strictSeparator: truealready rejects all of these (it only ever allowed[T], no whitespace alternation at all), so this only affects the default mode.Fix
[T\s]→[T ]in the mainiso8601regex, so onlyTor a literal space separates the date and time part. One-character change;iso8601StrictSeparatoris untouched since it never had this issue.Testing
Added
\t,\n,\f,\v, and a non-breaking space (U+00A0) separator case to the sharedinvalidISO8601array intest/validators.test.js, which is exercised by both the default-options test and thestrict = trueregression test (notstrictSeparator, which already had its own, unaffected assertions).validator.isISO8601("2009-01-01\t00:00:00") passed but should have failed, in both the default and strict-mode test blocks); restored.npx mocha --require @babel/register --reporter dot --recursive— 323/323 passing.eslinton both changed files — clean.