From 4d4dee62cbcf002deb8c846b4db2e69252fb3aa6 Mon Sep 17 00:00:00 2001 From: Diogo Zani Date: Sat, 28 Nov 2026 14:04:16 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20rejeita=20d=C3=ADgitos=20n=C3=A3o=20ASCI?= =?UTF-8?q?I=20na=20valida=C3=A7=C3=A3o=20de=20PIS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + README.md | 2 +- README_EN.md | 2 +- brutils/pis.py | 3 ++- tests/test_pis.py | 9 +++++++++ 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74c1db3f..0b04a120 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 5ba23fd5..887aa88e 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 0b9167a8..37b61337 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 723aca78..017881e8 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 45e9c729..88e1f8b2 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)