diff --git a/CHANGELOG.md b/CHANGELOG.md index 74c1db3..a35ba3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 5ba23fd..1a3e210 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/README_EN.md b/README_EN.md index 0b9167a..4820c20 100644 --- a/README_EN.md +++ b/README_EN.md @@ -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: diff --git a/brutils/voter_id.py b/brutils/voter_id.py index 7a1abd9..a218a21 100644 --- a/brutils/voter_id.py +++ b/brutils/voter_id.py @@ -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) ): diff --git a/tests/test_voter_id.py b/tests/test_voter_id.py index 738ec77..0a133c3 100644 --- a/tests/test_voter_id.py +++ b/tests/test_voter_id.py @@ -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"