Skip to content

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

Open
joaopedroassad wants to merge 1 commit into
brazilian-utils:mainfrom
joaopedroassad:fix-generate-cnpj-full-alphabet
Open

fix: generate alphanumeric CNPJs using the full A-Z alphabet#498
joaopedroassad wants to merge 1 commit into
brazilian-utils:mainfrom
joaopedroassad:fix-generate-cnpj-full-alphabet

Conversation

@joaopedroassad

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant