javascript
javascript copied to clipboard
fix: generate alphanumeric CNPJs using the full A-Z alphabet
Description
generateCnpj(2) builds the alphanumeric base from a restricted character set that drops the letters E, O, T, and U:
const VALID_CNPJ_CHARS = "0123456789ABCDFGHIJKLMNPQRSVWXYZ";
isValidCnpj(..., { version: 2 }) accepts the full [A-Z0-9] range, so the generator and the validator disagree: the generator can never emit a valid CNPJ containing E, O, T, or U, even though those CNPJs are valid.
This is the same restricted alphabet that #461 already removed from the alphanumeric sanitization path (closing #460); the generator was just left untouched at the time.
What changed
- Widened
VALID_CNPJ_CHARSingenerate-cnpj.tsto the full0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ. The checksum already usescharCodeAt(0) - 48, which is correct for every A-Z, so no other change is needed. - Added a test asserting that alphanumeric generation exercises the full alphabet, including the previously-excluded E, O, T, and U.
Testing
vp test run(full suite): 561 passed, 4 skipped.vp check: formatting and lint clean.