One function

CNPJ in alvarofpp/validate-docbr

The author described this change as fix: Resolve a issue #76. It counts as a record because the check below fails on the code as it stood at c3789082c and passes on 205c4aaf5, with nothing else changed between the two runs.

Fix saved2026-04-04
Sharing licenceMIT · LICENSE
Change size+16 0

What the code was meant to do, written into the code itself as a docstring

Classe referente ao Cadastro Nacional da Pessoa Jurídica (CNPJ). Aceita tanto o formato numérico tradicional quanto o novo formato alfanumérico. A validação reconhece ambos os formatos automaticamente.

The change

3232 if len(doc) != 14:
3333 return False
3434
35+ if self._is_repeated_characters(doc):
36+ return False
37+
3538 return self._generate_first_digit(doc) == doc[12] \
3639 and self._generate_second_digit(doc) == doc[13]
3740
110113
111114 remainder = total % 11
112115 return str(0 if remainder < 2 else 11 - remainder)
116+
117+ def _is_repeated_characters(self, doc: str) -> bool:
118+ """Verifica se o CNPJ contém apenas caracteres repetidos.
119+
120+ Exemplo: ``00000000000000``.
121+
122+ Args:
123+ doc: String com os caracteres do CNPJ.
124+
125+ Returns:
126+ True se todos os caracteres forem iguais.
127+ """
128+ return len(set(doc)) == 1

The check that tells the two apart

failpass·tests/test_CNPJ.py::TestCnpj::test_special_case

Check file tests/test_CNPJ.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itc3789082c017c5c27cb4303ea65c3fa93b0e4905
Broken version dated2026-04-04
Modulevalidate_docbr.CNPJ
Units changedCNPJ
Fingerprint1eb6deb0dc8ab694
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.