mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
feat: check payload length
This commit is contained in:
parent
02f83f5a94
commit
ce69434e71
2 changed files with 15 additions and 0 deletions
|
|
@ -110,6 +110,10 @@ async def _create_link(link_type, payload: str, encode=False):
|
|||
)
|
||||
raise ValueError(message)
|
||||
|
||||
if len(payload) > 64:
|
||||
message = "Payload must be up to 64 characters long."
|
||||
raise ValueError(message)
|
||||
|
||||
return f"https://t.me/{bot.username}?{link_type}={payload}"
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -76,3 +76,14 @@ class TestDeepLinking:
|
|||
encoded_payload = encode_payload(wrong_payload)
|
||||
|
||||
assert link == f'https://t.me/{USERNAME}?start={encoded_payload}'
|
||||
|
||||
async def test_64_len_payload(self):
|
||||
payload = "p" * 64
|
||||
link = await get_start_link(payload)
|
||||
assert link
|
||||
|
||||
async def test_too_long_payload(self):
|
||||
payload = "p" * 65
|
||||
print(payload, len(payload))
|
||||
with pytest.raises(ValueError):
|
||||
await get_start_link(payload)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue