From e09cd88c2debf47d69846430b106789f507c9b52 Mon Sep 17 00:00:00 2001 From: zjy-boom <2120518314@qq.com> Date: Sun, 22 Nov 2026 08:33:49 +0800 Subject: [PATCH] fix(dingtalk): split table cells after escaped backslashes (#8429) Co-authored-by: zjy-boom <174030947+zjy-boom@users.noreply.github.com> --- backend/app/channels/dingtalk.py | 24 ++++++++++-------------- backend/tests/test_dingtalk_channel.py | 7 +++++++ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/backend/app/channels/dingtalk.py b/backend/app/channels/dingtalk.py index 8fbb81eecb..742096b996 100644 --- a/backend/app/channels/dingtalk.py +++ b/backend/app/channels/dingtalk.py @@ -119,20 +119,16 @@ _TABLE_SEPARATOR_RE = re.compile(r"^\|[-:| ]+\|$", re.MULTILINE) def _split_markdown_table_row(row: str) -> list[str]: - r"""Keep escaped pipes and empty cells when removing the outer borders. - - Known boundary: the single-character lookbehind in the split pattern - cannot distinguish an escaped pipe (``\|``) from an escaped backslash - immediately followed by a real separator (``\\|``). A cell ending in a - literal backslash therefore absorbs the next cell: ``| foo\\ | bar |`` - splits as one cell instead of two. GFM counts consecutive backslashes - for this reason; doing so is out of scope here — this helper is - intentionally not a general Markdown parser. - """ - # ``(? **A**: {prefix}|suffix\n" if count % 2 else f"> **A**: {prefix}\n> **B**: suffix\n" + assert _convert_markdown_table(text) == expected + def test_fallback_adapter_preserves_table_values(self): text = "| Rule | Meaning |\n|---|---|\n| `foo\\|bar` | alternative |" assert _adapt_markdown_for_dingtalk(text) == "> **Rule**: **foo\\|bar**\n> **Meaning**: alternative\n"