🐛 Fix MessageTemplate improper behavior when no format spec (#947)

* 🧪 Add a test to figure out bug in #938

* ♻️ 🐛 Refactor rich message template formatting, fix #938
This commit is contained in:
Mix
2022-04-30 09:59:23 +08:00
committed by GitHub
parent f028575f2f
commit 95331bbb22
2 changed files with 47 additions and 27 deletions

View File

@ -32,6 +32,26 @@ def test_template_message():
assert str(formatted) == "custom-custom!text[fake:image]"
def test_rich_template_message():
Message = make_fake_message()
MS = Message.get_segment_class()
pic1, pic2, pic3 = (
MS.image("file:///pic1.jpg"),
MS.image("file:///pic2.jpg"),
MS.image("file:///pic3.jpg"),
)
template = Message.template("{}{}" + pic2 + "{}")
result = template.format(pic1, "[fake:image]", pic3)
assert result["image"] == Message([pic1, pic2, pic3])
assert str(result) == (
"[fake:image]" + escape_text("[fake:image]") + "[fake:image]" + "[fake:image]"
)
def test_message_injection():
Message = make_fake_message()