From 0eea397ef215d7480fb302f52818c0a70bfb2226 Mon Sep 17 00:00:00 2001 From: KANIKIG Date: Tue, 23 Jun 2026 14:33:53 +0800 Subject: [PATCH] fix(weixin): stop line wrapping from breaking markdown links --- gateway/platforms/weixin.py | 1 + tests/gateway/test_weixin.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/gateway/platforms/weixin.py b/gateway/platforms/weixin.py index 4ce487193211d..89304e742db09 100644 --- a/gateway/platforms/weixin.py +++ b/gateway/platforms/weixin.py @@ -719,6 +719,7 @@ def _wrap_copy_friendly_lines_for_weixin(content: str) -> str: or not stripped or stripped.startswith("|") or _TABLE_RULE_RE.match(stripped) + or _MARKDOWN_LINK_RE.search(stripped) ): wrapped.append(line) continue diff --git a/tests/gateway/test_weixin.py b/tests/gateway/test_weixin.py index 5169666e8bafc..f3f1ceec50bd8 100644 --- a/tests/gateway/test_weixin.py +++ b/tests/gateway/test_weixin.py @@ -68,6 +68,21 @@ def test_format_message_wraps_long_plain_lines_for_copying(self): assert all(len(line) <= weixin.WEIXIN_COPY_LINE_WIDTH for line in formatted.splitlines()) assert " ".join(formatted.split()) == " ".join(content.split()) + def test_format_message_does_not_wrap_long_markdown_links(self): + adapter = _make_adapter() + + content = ( + "Read [Designcenter NX中的分析载荷]" + "(https://example.com/articles/" + + "a" * weixin.WEIXIN_COPY_LINE_WIDTH + + ")" + ) + + formatted = adapter.format_message(content) + + assert formatted == content + assert "\n" not in formatted + def test_format_message_does_not_wrap_long_code_block_lines(self): adapter = _make_adapter()