diff --git a/CHANGELOG.md b/CHANGELOG.md index 74c1db3..0b04a12 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_pis` aceitava dígitos de outros alfabetos, como `٩`, e levantava `ValueError` com algarismos sobrescritos, como `²` [#813](https://github.com/brazilian-utils/python/issues/813) - 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..887aa88 100644 --- a/README.md +++ b/README.md @@ -915,7 +915,7 @@ Referências: Argumentos: -- pis (str): Número PIS como uma string com o comprimento apropriado. +- pis (str): Número PIS como uma string de 11 dígitos de 0 a 9. Retorna: diff --git a/README_EN.md b/README_EN.md index 0b9167a..37b6133 100644 --- a/README_EN.md +++ b/README_EN.md @@ -915,7 +915,7 @@ References: Args: -- pis (str): PIS number as a string with the proper length. +- pis (str): PIS number as an 11-digit string of ASCII digits (0-9). Returns: diff --git a/brutils/pis.py b/brutils/pis.py index 723aca7..017881e 100644 --- a/brutils/pis.py +++ b/brutils/pis.py @@ -66,7 +66,7 @@ def is_valid(pis: str) -> bool: given `PIS` match its base number. Args: - pis (str): PIS number as a string of proper length. + pis (str): PIS number as an 11-digit string of ASCII digits (0-9). Returns: bool: True if PIS is valid, False otherwise. @@ -82,6 +82,7 @@ def is_valid(pis: str) -> bool: return ( isinstance(pis, str) and len(pis) == 11 + and pis.isascii() and pis.isdigit() and pis[-1] == str(_checksum(pis[:-1])) ) diff --git a/tests/test_pis.py b/tests/test_pis.py index 45e9c72..88e1f8b 100644 --- a/tests/test_pis.py +++ b/tests/test_pis.py @@ -25,6 +25,15 @@ def test_is_valid(self): self.assertIs(is_valid("123pis"), False) self.assertIs(is_valid("123456789ab"), False) + # When PIS contains digits from other alphabets, returns False + self.assertIs(is_valid("١2038619494"), False) + self.assertIs(is_valid("12038619494"), False) + + # When PIS contains superscript digits, returns False instead of + # raising ValueError + self.assertIs(is_valid("1203861949" + "⁴"), False) + self.assertIs(is_valid("²" * 11), False) + # When checksum digit doesn't match last digit, returns False self.assertIs(is_valid("11111111111"), False) self.assertIs(is_valid("11111111215"), False)