javascript icon indicating copy to clipboard operation
javascript copied to clipboard

fix: generate alphanumeric CNPJs using the full A-Z alphabet

Open joaopedroassad opened this issue 5 months ago • 0 comments

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_CHARS in generate-cnpj.ts to the full 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ. The checksum already uses charCodeAt(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.

joaopedroassad avatar Jun 24 '26 17:06 joaopedroassad