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_voter_id` aceitava dígitos de outros alfabetos, como `٨`, e levantava `ValueError` com algarismos sobrescritos, como `²` [#817](https://github.com/brazilian-utils/python/issues/817)
- 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 @@ -1123,7 +1123,7 @@ Referências:

Argumentos:

- voter_id (str): string representando o número do título de eleitor a ser verificado.
- voter_id (str): string representando o número do título de eleitor a ser verificado (apenas dígitos de 0 a 9).

Retorna:

Expand Down
2 changes: 1 addition & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ References:

Args:

- voter_id(str): string representing the voter id to be verified.
- voter_id(str): string representing the voter id to be verified (ASCII digits 0-9 only).

Returns:

Expand Down
7 changes: 5 additions & 2 deletions brutils/voter_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ def is_valid(voter_id: str) -> bool:
- http://clubes.obmep.org.br/blog/a-matematica-nos-documentos-titulo-de-eleitor/

Args:
voter_id(str): string representing the voter id to be verified.
voter_id(str): string representing the voter id to be verified
(ASCII digits 0-9 only).

Returns:
bool: True if the voter id is valid. False otherwise.
"""

# ensure voter_id only contains numerical characters and has a valid length
# ensure voter_id only contains ASCII numerical characters and has a
# valid length
if (
not isinstance(voter_id, str)
or not voter_id.isascii()
or not voter_id.isdigit()
or not _is_length_valid(voter_id)
):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_voter_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ def test_invalid_characters(self):
self.assertIs(is_valid(invalid_characters), False)
self.assertIs(is_valid(invalid_characters_space), False)

def test_non_ascii_digits(self):
# When voter id contains digits from other alphabets, returns False
self.assertIs(is_valid("٢17633460930"), False)
self.assertIs(is_valid("217633460930"), False)

# When voter id contains superscript digits, returns False instead
# of raising ValueError
self.assertIs(is_valid("21763346093" + "⁰"), False)
self.assertIs(is_valid("²17633460930"), False)

def test_valid_special_case(self):
# Test a valid edge case (SP & MG with 13 digits)
valid_special = "3244567800167"
Expand Down
Loading