From 67b6bd3038886eccca2dc466e324aff1135715c3 Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Thu, 24 Sep 2026 02:53:49 +0800 Subject: [PATCH] fix(commands): stop /debug from nesting blockquotes on long posts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit debug_report wrapped every caption in
, but preview_caption for a post over CAPTION_QUOTE_TEXT_CHARS already carries quote_long_caption's expandable blockquote — and the API rejects nested entities, so /debug on any long post answered 400. The wrapper now skips a caption that already carries a blockquote, exactly the rule quote_long_caption itself applies; the new test pins that the quoted caption passes through with a single blockquote while the existing test keeps pinning the wrap for ordinary captions. --- crates/xmedia-bot/src/handlers/commands.rs | 44 +++++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/crates/xmedia-bot/src/handlers/commands.rs b/crates/xmedia-bot/src/handlers/commands.rs index f874798..23370bf 100644 --- a/crates/xmedia-bot/src/handlers/commands.rs +++ b/crates/xmedia-bot/src/handlers/commands.rs @@ -809,11 +809,17 @@ fn debug_report( lines.push(format!("sensitive: {sensitive}")); // The caption is wrapped in a
so the report (an HTML // message) shows it exactly as it will render in the sent media caption - // — escaped text and links included. - lines.push(format!( - "caption:
{}
", - x_media::site::truncate_caption(caption) - )); + // — escaped text and links included. A long post's caption already + // carries quote_long_caption's expandable blockquote and the API rejects + // nested ones (the same rule quote_long_caption applies), so that caption + // is shown unwrapped instead of failing to send. + let caption = x_media::site::truncate_caption(caption); + let caption = if caption.contains("{caption}
") + }; + lines.push(format!("caption: {caption}")); lines.push(format!("media ({}):", media.len())); for (i, item) in media.iter().enumerate() { let kind = match item { @@ -1091,6 +1097,34 @@ mod tests { ); } + #[test] + fn debug_report_does_not_nest_a_quoted_caption() { + // A long post's preview_caption already carries quote_long_caption's + //
; wrapping it again produced nested + // blockquotes, which the API rejects — /debug on any long post 400'd. + let quoted = "intro
long text
"; + let report = debug_report( + "https://x.com/u/status/1", + "twitter", + "https://x.com/u/status/1", + "t", + "c", + None, + false, + quoted, + &[], + ); + assert!( + report.contains(&format!("caption: {quoted}")), + "the quoted caption must be shown as-is: {report}" + ); + assert_eq!( + report.matches("