You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
isFloat builds a literal undefined separator for an unknown locale #2862
When options.locale is not a key of decimal, the lookup yields undefined,
which stringifies into the pattern as the literal text undefined. The
preceding \\ produces \undefined, and since \u is not followed by four hex
digits the escape degrades to a literal u in non-unicode mode. The compiled
separator is therefore the eight-character string undefined.
There is no error and no fallback to ., so an unrecognized locale silently
produces a validator that accepts nonsense and rejects ordinary decimals.
Examples
constvalidator=require('validator');// 13.15.35validator.isFloat('3undefined5',{locale: 'no-such'});// truevalidator.isFloat('3.5',{locale: 'no-such'});// false// Plausible tags that are simply not in the table behave the same wayvalidator.isFloat('3undefined5',{locale: 'de-CH'});// true
de-CH is the case most likely to reach production: it is a real BCP 47 tag
and a reasonable thing to pass, but it is not among the sixty-eight keys in decimal, so any Swiss German user silently gets the broken validator.
Reproductions
The Examples block above runs as-is on Node after npm install [email protected]; no harness or scaffolding needed.
Additional context
Other locale-aware validators reject an unknown locale with throw new Error('Invalid locale ...'). Matching that here, or falling back to ., would both be an improvement over building an unusable pattern.
Validator.js version: 13.15.35
Node.js version: v26.7.0
OS platform: Linux
Hi 👋 I'd like to work on this. Could it be assigned to me (@Saifjafri212213)? I'd make isFloat handle an unknown locale explicitly (throw an error like the other locale-aware validators, or fall back to ., whichever the maintainers prefer) instead of building undefined into the regex, and add tests for it. Thanks!
Activity
Saifjafri212213 commentedon Oct 7, 2026
Hi 👋 I'd like to work on this. Could it be assigned to me (@Saifjafri212213)? I'd make
isFloathandle an unknown locale explicitly (throw an error like the other locale-aware validators, or fall back to., whichever the maintainers prefer) instead of buildingundefinedinto the regex, and add tests for it. Thanks!