fix(renavam): reject negative and fractional numbers - #592
hyanmandian merged 1 commit into
Conversation
|
@kwy404 is attempting to deploy a commit to the Hyan Mandian's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Awesome @kwy404! Thanks! I gonna add it as part of 2.5.0 release! |
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #592 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 186 186
Lines 2069 2069
Branches 613 613
=========================================
Hits 2069 2069
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@claude could you please check if there's any other "isValid" utility that should use the isLookupCode? if so, create one PR stacked on top of this one fixing those too! |
|
@kwy404 could you rebase? I fixed the build issue! |
isValidRenavam turned a number into a string and then dropped the separators, so the minus sign and the decimal point of a number were read as mask characters and -639884962 and 63988496.2 both validated as the RENAVAM 639884962. A number is now only read as a RENAVAM when it is a non-negative safe integer, through the isLookupCode guard that the code lookups and isValidCreditCard already use since 9cb73d0. Strings keep their mask handling unchanged. Signed-off-by: kwy404 <thekaway404@gmail.com>
7fe2f8c to
93aca38
Compare
|
Rebased on main, thanks! The RENAVAM tests pass locally (28 of 28). |
What does this PR do?
Root cause:
isValidRenavamaccepts a number, turns it into a string withtoString()and then strips the mask characters withSEPARATORS_REGEX(whitespace, dot, hyphen). In a number, the minus sign and the decimal point are not a mask, but they are removed all the same, so a negative or fractional number is validated as the digits that are left:Fix: the first guard now uses
isLookupCode, the helper added in 9cb73d0 ("reject negative, fractional and unsafe numbers in every code lookup") and already used byisValidCreditCard,isValidNcm,isValidCfop,isValidCstandisValidCsosn. A string is handled exactly as before; a number is only read as a RENAVAM when it is a non-negative safe integer. The JSDoc gets one sentence and one example saying so.Test: a new case in
is-valid-renavam.test.ts, "when it is a negative or fractional number", expectsfalsefor-639_884_962and63_988_496.2. It fails on main (expected true to be false) and passes with the fix.Checklist
feat: ...,fix: ...,docs: ...).npm test).docs/utilities.md(English)docs/pt-br/utilities.md(Portuguese)npm run checkpasses locally (format, lint, types).npm run build:llmsif I toucheddocs/utilities.md(the Check workflow fails whendocs/llms.txtis stale): not touched.Additional context
Number.MAX_SAFE_INTEGER(639_884_962in the existing test still passes). Only negative and fractional numbers, which are never a RENAVAM, stop validating, the same change 9cb73d0 made forisValidCreditCard.docs/utilities.mdanddocs/pt-br/utilities.mdare all strings and behave the same, so the docs pages are unchanged.vp checkclean;vp test run --coveragewith 6132 tests passing and 100% coverage;stryker run --mutate src/is-valid-renavam/is-valid-renavam.tswith 27 of 27 mutants killed (score 100);jscpd,knipandnpm run check:apiclean.