fix(tg_bot): 放宽退订链接 URL 长度上限,长 tracking 链接不被误杀
实测 D:\DOWNLOADS\mail_bot.db 中 ChatGPT 推广邮件的退订链接 (https://r.openai.com/asm/unsubscribe/?...) 长度 700+ 字符, 而 _link_buttons 的 len(url) < 200 校验会把它过滤掉,导致 即使 AI 提取出退订链接、显示层也修好了,按钮依然不显示。 上限 200 -> 2048(Telegram inline URL 按钮安全范围)。 新增回归测试 test_long_unsub_url_rendered / test_oversized_url_filtered, 共 9 个用例全部通过。
This commit is contained in:
2 files changed
+24
-4
No files matched your search
@@ -75,7 +75,7 @@ def test_unsub_link_sorted_before_other_links():
|
||||
|
||||
|
||||
def test_invalid_url_filtered():
|
||||
"""非法 URL(非 http、多重协议头、超长)被过滤"""
|
||||
"""非法 URL(非 http、多重协议头)被过滤"""
|
||||
links = [
|
||||
{"text": "退订", "url": "javascript:alert(1)"},
|
||||
{"text": "退订", "url": "https://x.com/https://evil.com"},
|
||||
@@ -83,4 +83,23 @@ def test_invalid_url_filtered():
|
||||
]
|
||||
rows = _link_buttons(links)
|
||||
assert len(rows) == 1
|
||||
assert rows[0][0]["url"] == "https://ok.example.com/unsub"
|
||||
assert rows[0][0]["url"] == "https://ok.example.com/unsub"
|
||||
|
||||
|
||||
def test_long_unsub_url_rendered():
|
||||
"""长 tracking 退订链接(如 OpenAI 的 >700 字符)必须渲染,不能被长度过滤误杀"""
|
||||
url = "https://r.openai.com/asm/unsubscribe/?user_id=108370056&data=" + "x" * 700
|
||||
assert len(url) > 200
|
||||
links = [{"text": "取消订阅", "url": url}]
|
||||
rows = _link_buttons(links)
|
||||
assert len(rows) == 1
|
||||
assert rows[0][0]["url"] == url
|
||||
assert "🔕" in rows[0][0]["text"]
|
||||
|
||||
|
||||
def test_oversized_url_filtered():
|
||||
"""超过 2048 的 URL 仍被过滤"""
|
||||
url = "https://example.com/" + "x" * 2100
|
||||
links = [{"text": "退订", "url": url}]
|
||||
rows = _link_buttons(links)
|
||||
assert rows == []
|
||||
Reference in New Issue
Block a user