Skip to content

fix: corrects sanitization to accept the entire alphabet in alphanume…#461

Open
lindsay-qive wants to merge 2 commits intobrazilian-utils:mainfrom
lindsay-qive:fix/cnpj-alfanumerico-sanitize
Open

fix: corrects sanitization to accept the entire alphabet in alphanume…#461
lindsay-qive wants to merge 2 commits intobrazilian-utils:mainfrom
lindsay-qive:fix/cnpj-alfanumerico-sanitize

Conversation

@lindsay-qive
Copy link

Description

This PR fixes the sanitization logic for the alphanumeric CNPJ (version 2), which was incorrectly restricting the allowed characters and silently removing valid letters (such as 'E', 'O', 'T', 'U').

Closes #460

What was changed

  • Replaced the manual for loop and the restricted allowedChars string with a standard .replace(/[^A-Za-z0-9]/g, '').toUpperCase().
  • The code now correctly accepts all 26 letters of the alphabet.
  • As per official guidelines, the blocking of sensitive or offensive word combinations is handled at the origin (by the Receita Federal during CNPJ generation), and receiving systems should accept the full [A-Z0-9] range.

Evidence / Official Context

According to the official FAQ document released by the Brazilian Federal Revenue (Receita Federal do Brasil), the alphanumeric CNPJ uses the [A-Z0-9] base[cite: 22].

Furthermore, the official example provided by the government for calculating the Verification Digit (Módulo 11) explicitly uses the letter E: 12.ABC.345/01DE-35. The previous allowedChars implementation was stripping this letter out, rendering valid official examples invalid.

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.

Falta de letras na validação e formatação de CNPJ Alfanumérico

1 participant