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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Utilitário `legal_process` [#743](https://github.com/brazilian-utils/python/pull/743)

## [2.4.0] - 2026-04-20

### Added
Expand Down
15 changes: 14 additions & 1 deletion brutils/legal_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ def format_legal_process(legal_process_id: str) -> str | None:
None
"""

if legal_process_id.isdigit() and len(legal_process_id) == 20:
if (
isinstance(legal_process_id, str)
and legal_process_id.isdigit()
and len(legal_process_id) == 20
):
capture_fields = r"(\d{7})(\d{2})(\d{4})(\d)(\d{2})(\d{4})"
include_chars = r"\1-\2.\3.\4.\5.\6"

Expand Down Expand Up @@ -92,7 +96,16 @@ def is_valid(legal_process_id: str) -> bool:
False
"""

if not isinstance(legal_process_id, str):
return False

clean_legal_process_id = remove_symbols(legal_process_id)
if (
not clean_legal_process_id.isdigit()
or len(clean_legal_process_id) != 20
):
return False

DD = clean_legal_process_id[7:9]
J = clean_legal_process_id[13:14]
TR = clean_legal_process_id[14:16]
Expand Down
4 changes: 4 additions & 0 deletions tests/test_legal_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def test_format_legal_process(self):
self.assertIsNone(format_legal_process("2314194582005507"))
self.assertIsNone(format_legal_process("0000000000000000000000000"))
self.assertIsNone(format_legal_process("0000000000000000000asdasd"))
self.assertIsNone(format_legal_process(None))
self.assertIsNone(format_legal_process(123))

def test_remove_symbols(self):
self.assertEqual(
Expand Down Expand Up @@ -73,6 +75,8 @@ def test_is_valid(self):
self.assertIs(is_valid("455323469202340251"), False)
self.assertIs(is_valid("455323469202340257123123123"), False)
self.assertIs(is_valid("455323423QQWEQWSsasd&*(()"), False)
self.assertIs(is_valid(None), False)
self.assertIs(is_valid(123), False)
self.assertIsInstance(is_valid("455323423QQWEQWSsasd&*(()"), bool)


Expand Down
Loading