fix(isFloat): throw on invalid locale instead of an "undefined" separator - #2890
Open
yu2971512385-ui wants to merge 1 commit into
Open
yu2971512385-ui wants to merge 1 commit into
yu2971512385-ui wants to merge 1 commit into
Conversation
…ator When `options.locale` was not a key of the `decimal` separator map, isFloat interpolated the resulting `undefined` directly into its RegExp, compiling an 8-character `undefined` decimal separator. Unknown locales then silently accepted strings like "3undefined5" while rejecting ordinary decimals such as "3.5", with no error and no fallback. Validate the locale up front and throw `Invalid locale '<locale>'`, matching isDecimal and the other locale-aware validators. Fixes validatorjs#2862 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2890 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 114 114
Lines 2599 2601 +2
Branches 658 659 +1
=========================================
+ Hits 2599 2601 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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 #2862.
The bug
isFloatinterpolates the locale separator straight into aRegExp:When
options.localeis not a key ofdecimal, the lookup yieldsundefined, which stringifies into the pattern as the literal textundefined(the preceding\+udegrades to a literalu). The compiled separator becomes the 8‑character stringundefined, so an unrecognized locale silently accepts nonsense and rejects ordinary decimals — with no error and no fallback:The fix
Validate
options.localeagainstdecimalup front and throwInvalid locale '<locale>'when it is unknown. This mirrorsisDecimal(which shares the samedecimalmap) and the other locale-aware validators (isAlpha,isAlphanumeric,isMobilePhone,isPostalCode, …), which already throw on an invalid locale. Absent/known locales are unaffected.Tests
Added an
isFloat"should error on invalid locale" case alongside the existingisDecimalone. Verified it fails on the unpatched source and passes with the fix; the full suite (npm test) is green.Checklist
🤖 Generated with Claude Code