Skip to content

Commit 5a2c80e

Browse files
committed
Fix the text validation in header blocks
1 parent c4969ac commit 5a2c80e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

slack/web/classes/blocks.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ def __init__(
387387

388388
class HeaderBlock(Block):
389389
type = "header"
390-
text_max_length = 3000
390+
text_max_length = 150
391391

392392
@property
393393
def attributes(self) -> Set[str]:
@@ -411,3 +411,7 @@ def __init__(
411411
@JsonValidator("text attribute must be specified")
412412
def _validate_text_populated(self):
413413
return self.text is not None
414+
415+
@JsonValidator(f"text attribute cannot exceed {text_max_length} characters")
416+
def _validate_alt_text_length(self):
417+
return self.text is None or len(self.text.text) <= self.text_max_length

tests/web/classes/test_blocks.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,3 +713,21 @@ def test_document(self):
713713
}
714714
self.assertDictEqual(input, HeaderBlock(**input).to_dict())
715715
self.assertDictEqual(input, Block.parse(input).to_dict())
716+
717+
def test_text_length_150(self):
718+
input = {
719+
"type": "header",
720+
"block_id": "budget-header",
721+
"text": {"type": "plain_text", "text": "1234567890" * 15},
722+
}
723+
HeaderBlock(**input).validate_json()
724+
725+
def test_text_length_151(self):
726+
input = {
727+
"type": "header",
728+
"block_id": "budget-header",
729+
"text": {"type": "plain_text", "text": ("1234567890" * 15) + "1"},
730+
}
731+
with self.assertRaises(SlackObjectFormationError):
732+
HeaderBlock(**input).validate_json()
733+

0 commit comments

Comments
 (0)