Replace @randyd45/curp-validation with validate-curp - #296
Merged
Merged
Conversation
The curp lib validated the CURP check digit, but its replacement @randyd45/curp-validation only checks the format regex, so 9 out of 10 possible check digits on any structurally-valid CURP were accepted. validate-curp (MIT, same author as validate-rfc) restores check-digit validation and additionally validates the state code and RENAPO's forbidden-word list, matching the original curp lib's behavior.
ricardobcl
force-pushed
the
bugfix/restore-curp-check-digit-validation
branch
from
August 31, 2026 15:32
e27838d to
c83f085
Compare
Prado
approved these changes
Sep 2, 2026
There was a problem hiding this comment.
🟡 Changes recommended
The new validate-curp integration should defensively handle a possible null return to avoid runtime TypeError and ensure invalid CURPs consistently raise a Violation.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR restores strict Mexican CURP validation in the CurpNumber assert by switching from a format-only validator to validate-curp, aligning CURP validation behavior with the existing RfcNumber assert (including check-digit verification) and adding a regression test.
Changes:
- Replace
@randyd45/curp-validationwithvalidate-curpacross runtime docs/types and dependency declarations. - Update
CurpNumberassert implementation to usevalidate-curp. - Add a negative test case for invalid CURP check digits.
File summaries
| File | Description |
|---|---|
| yarn.lock | Removes @randyd45/curp-validation and adds validate-curp lock entry. |
| test/asserts/curp-number-assert.test.js | Adds a regression test for invalid CURP check digit handling. |
| src/types/index.d.ts | Updates the documented peer dependency for curpNumber(). |
| src/asserts/curp-number-assert.js | Switches CURP validation logic to validate-curp. |
| README.md | Updates dependency table and link reference to validate-curp. |
| package.json | Replaces old CURP validator with validate-curp in dev/peer/optional peer deps. |
Review details
- Files reviewed: 4/6 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+44
to
46
| if (!validateCurp(value).isValid) { | ||
| throw new Violation(this, value, { value: 'must_be_a_valid_curp_number' }); | ||
| } |
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.
Description
v11.0.0 replaced the GPL-licensed
curplib with@randyd45/curp-validation(#287), but the two are not equivalent:curp.validar()validated the CURP check digit, while@randyd45/curp-validation'sisFormatValid()only tests the format regex — the 18th character is matched by(\d)but never verified. Both libraries use the same regex, so the swap silently made the assert strictly more permissive.Verified empirically — same 17-character prefix, all ten possible check digits:
curp@1.2.3@randyd45/curp-validation@1.0.4SABC560626MDFLRN01(correct digit)SABC560626MDFLRN00,02…099 of 10 previously-rejected values pass v11. The check digit is a weighted mod-10 sum over the 17 preceding characters — it is what catches single-character typos and transpositions anywhere in the CURP.
This PR replaces
@randyd45/curp-validationwithvalidate-curp(MIT, same author as thevalidate-rfclib already backing theRfcNumberassert), mirroring theRfcNumberassert one-to-one.validate-curprestores check-digit validation — its algorithm is identical to the originalcurplib's (same 37-character dictionary, weights18 - i, mod 10) — and additionally validates the state code (includingNE) and RENAPO's forbidden-word list (identical tocurp's 81-wordmalasPalabraslist).Behavioral notes:
validate-rfc,validate-curpnormalizes input before validating (trim, uppercase, strip non-alphanumerics), so e.g. lowercase CURPs are now accepted — consistent with howRfcNumberbehaves today.curp.validar(), which never checked it (onlygenerar()substituted forbidden words). Genuine RENAPO-issued CURPs never carry those prefixes.Also adds a check-digit negative test — the test that would have caught this in #287.
Related issues
Follow-up to #287. Affects uphold/backend#18451.
Impacted areas
CurpNumberassert.Steps to reproduce or test
Development
yarn test523/523 passing, including the new check-digit case.
QA
N/A
Checklist
Breaking Changeif it applies.package.json.Deploy notes
Peer dependency change (
@randyd45/curp-validation→validate-curp), so the next release should be a major (v12.0.0). Consumers must swap the optional peer dependency when upgrading.