Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- `is_valid_cep` e `format_cep` aceitavam dígitos não ASCII, como `²` [#805](https://github.com/brazilian-utils/python/pull/805)
- Cálculo do dígito verificador em `is_valid_legal_process` e `generate_legal_process`, que rejeitava números de processo reais e gerava números inválidos [#785](https://github.com/brazilian-utils/python/pull/785)

## [2.5.0] - 2026-06-30
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ Exemplo:

Verifica se um CEP (Código de Endereçamento Postal) brasileiro é válido.
Para que um CEP seja considerado válido, a entrada deve ser uma string contendo
exatamente 8 dígitos. Esta função não verifica se o CEP é um CEP real, pois
exatamente 8 dígitos de 0 a 9. Esta função não verifica se o CEP é um CEP real, pois
valida apenas o formato da string.

Argumentos:
Expand Down
2 changes: 1 addition & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ Example:
### is_valid_cep

Checks if a Brazilian CEP (Postal Code) is valid.
To be considered valid, the input must be a string containing exactly 8 digits.
To be considered valid, the input must be a string containing exactly 8 digits (0-9).
This function does not verify if the CEP is a real postal code; it only
validates the format of the string.

Expand Down
9 changes: 7 additions & 2 deletions brutils/cep.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def is_valid(cep: str) -> bool:
Checks if a CEP (Postal Code) is valid.

To be considered valid, the input must be a string containing exactly 8
digits.
ASCII digits (0-9).
This function does not verify if the CEP is a real postal code; it only
validates the format of the string.

Expand All @@ -89,7 +89,12 @@ def is_valid(cep: str) -> bool:
https://en.wikipedia.org/wiki/Código_de_Endereçamento_Postal
"""

return isinstance(cep, str) and len(cep) == 8 and cep.isdigit()
return (
isinstance(cep, str)
and len(cep) == 8
and cep.isascii()
and cep.isdigit()
)


def generate() -> str:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_cep.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def test_is_valid(self):
# When CEP does not contain only digits, returns False
self.assertIs(is_valid("1234567-"), False)

# When CEP contains non-ASCII digits, returns False
self.assertIs(is_valid("²" * 8), False)
self.assertIs(is_valid("01310200"), False)
self.assertIs(is_valid("٠١٣١٠٢٠٠"), False)

# When CEP is valid
self.assertIs(is_valid("99999999"), True)
self.assertIs(is_valid("88390000"), True)
Expand Down
Loading