fix(feishu): sanitize unsupported markdown and route tables through post/md - #62354
fix(feishu): sanitize unsupported markdown and route tables through post/md#62354linhuchong wants to merge 1 commit into
Conversation
…ost/md The Feishu adapter forced markdown tables into plain-text mode, rendering them as raw pipe characters on the client. Meanwhile, other unsupported syntax (HTML details/summary, kbd, mark, span, sup/sub, ==highlight==, Mermaid, inline images) passed through unmodified, causing blank or malformed output. Changes: - Route tables through post/md instead of forcing text mode - Add _sanitize_feishu_markdown() to rewrite unsupported syntax into Feishu-compatible equivalents (e.g. ==highlight== -> **bold**, <details>/<summary> -> **title**\nbody, Mermaid -> fenced text block) - Override extract_images() to skip auto-downloading third-party image URLs that would block text replies - Apply sanitization in all text-fallback paths The table rendering workaround in _build_outbound_payload (commit 8e18d10) is superseded by this change.
Related: this joins the long-standing Feishu markdown-table cluster (#53355, #57566, #33800, #61647, canonical native-card #12114). The table-rendering half here (remove the force-text branch, route tables through post/md) overlaps those competing PRs; this PR additionally adds a broader |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for addressing Feishu output compatibility. The current implementation needs revision before its table-routing and sanitizer changes are safe.
Problems
plugins/platforms/feishu/adapter.py:4673-4674reverses the current workaround, butmainstill documents thatpost/mdtable rendering produced blank client messages (plugins/platforms/feishu/adapter.py:4525-4530; commit8e18d1031). Please provide an integration-backed reason to change that route._sanitize_feishu_markdown()sanitizes the whole input atadapter.py:646before it tracks fences at:655; thus HTML-like content inside fenced code is modified despite the stated code-preservation guarantee.- Standard fenced Mermaid enters the generic fence branch at
:655and never reaches the Mermaid conversion at:661. - The one-file diff adds no tests for these new delivery paths; current
tests/gateway/test_feishu.pyonly covers generic md-post construction around:2577.
Suggested changes
- Preserve/protect fenced content before sanitization, explicitly handle
```mermaidfences, and add focused adapter tests. Keep the existing table fallback unless a real Feishu rendering test demonstrates that post/md now renders tables.
Automated hermes-sweeper review.
| if not content: | ||
| return content | ||
|
|
||
| normalized = _unwrap_feishu_unsupported_html(content.replace("\r\n", "\n")) |
There was a problem hiding this comment.
This normalizes HTML before the fence-state loop starts, so <kbd>, <details>, and similar source inside a fenced code block are changed before lines 655-676 can preserve the block. Please protect/split fenced regions first, then sanitize only prose.
| while index < len(lines): | ||
| raw_line = lines[index] | ||
| stripped = raw_line.strip() | ||
| if _MARKDOWN_FENCE_OPEN_RE.match(stripped) or _MARKDOWN_FENCE_CLOSE_RE.match(stripped): |
There was a problem hiding this comment.
A standard fenced Mermaid block begins with ```mermaid, so this generic fence branch preserves it and its graph/`flowchart` body never reaches the conversion at line 661. Detect the Mermaid fence language before this branch and cover it with a test.
| text_payload = {"text": content} | ||
| safe_content = _sanitize_feishu_markdown(content) | ||
| if _MARKDOWN_TABLE_RE.search(safe_content): | ||
| return "post", _build_markdown_post_payload(safe_content) |
There was a problem hiding this comment.
This reverses the current workaround whose documented purpose is preventing blank table messages in Feishu post/md (8e18d1031; current main adapter.py:4525-4530). Please retain text routing until a Feishu integration test or authoritative API evidence proves post/md now renders these tables.
Problem
The Feishu adapter forced markdown tables into plain-text mode (
msg_type="text"), rendering them as raw pipe characters on the client. Other unsupported syntax (HTML<details>/<summary>,<kbd>,<mark>,<span>,<sup>/<sub>,==highlight==, Mermaid diagrams, inline images) passed through unmodified, causing blank or malformed output.Root Cause
_build_outbound_payloaddetected markdown tables via_MARKDOWN_TABLE_REand routed them to plain text (commit8e18d1031). No sanitization layer existed for other Feishu-unsupported syntax.Changes
post/mdinstead of forcing plain-text mode. Feishu postmdelements support GFM tables._sanitize_feishu_markdown()— rewrites unsupported syntax into Feishu-compatible equivalents:==highlight==→**bold**<details>/<summary>→**title**\nbody<kbd>,<mark>,<span>,<div>→ stripped<sup>/<sub>→ strippedtextcode block with descriptive labelextract_images()to skip auto-downloading third-party image URLs that would block text replies on the Feishu send path. ExplicitMEDIA:/send_image/send_image_filestill use the native upload flow.Test Plan
==highlight==— verify it renders as bold<details><summary>— verify it renders as bold title + bodyNotes
_MARKDOWN_TABLE_REworkaround (commit8e18d1031, 2026-04-22) is superseded by this change.post/md→text(with sanitization).