Skip to content

isISO8601 accepts any whitespace as the date-time separator #2861

Description

@uhop

Describe the bug

The date and time parts are separated by [T\s] in the default pattern. \s
matches tab, newline, form feed, vertical tab, and non-breaking space in
addition to a plain space, so all of them are accepted as ISO 8601 separators.

ISO 8601 itself permits only T. RFC 3339 §5.6 additionally allows a space by
convention, which is presumably why the class is there, but neither permits the
rest of \s.

Examples

const validator = require('validator'); // 13.15.35

validator.isISO8601('2009-01-01\t00:00:00');     // true (tab)
validator.isISO8601('2009-01-01\n00:00:00');     // true (newline)
validator.isISO8601('2009-01-01\f00:00:00');     // true (form feed)
validator.isISO8601('2009-01-01\v00:00:00');     // true (vertical tab)
validator.isISO8601('2009-01-01 00:00:00'); // true (non-breaking space)

Reproductions

The Examples block above runs as-is on Node after
npm install validator@13.15.35; no harness or scaffolding needed.

Additional context

strictSeparator: true rejects every one of these, so there is a working
opt-out. If the intent of the default mode is RFC 3339 leniency, then [T ]
expresses that exactly, whereas [T\s] admits four more characters that no
relevant specification allows. A newline in particular is worth rejecting,
since it lets a two-line input pass a single-value check.

Validator.js version: 13.15.35
Node.js version: v26.7.0
OS platform: Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions