mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-09-28 00:02:12 +00:00
fix(commands): stop /debug from nesting blockquotes on long posts
debug_report wrapped every caption in <blockquote>, 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.
This commit is contained in:
@@ -809,11 +809,17 @@ fn debug_report(
|
|||||||
lines.push(format!("sensitive: {sensitive}"));
|
lines.push(format!("sensitive: {sensitive}"));
|
||||||
// The caption is wrapped in a <blockquote> so the report (an HTML
|
// The caption is wrapped in a <blockquote> so the report (an HTML
|
||||||
// message) shows it exactly as it will render in the sent media caption
|
// message) shows it exactly as it will render in the sent media caption
|
||||||
// — escaped text and links included.
|
// — escaped text and links included. A long post's caption already
|
||||||
lines.push(format!(
|
// carries quote_long_caption's expandable blockquote and the API rejects
|
||||||
"caption: <blockquote>{}</blockquote>",
|
// nested ones (the same rule quote_long_caption applies), so that caption
|
||||||
x_media::site::truncate_caption(caption)
|
// is shown unwrapped instead of failing to send.
|
||||||
));
|
let caption = x_media::site::truncate_caption(caption);
|
||||||
|
let caption = if caption.contains("<blockquote") {
|
||||||
|
caption
|
||||||
|
} else {
|
||||||
|
format!("<blockquote>{caption}</blockquote>")
|
||||||
|
};
|
||||||
|
lines.push(format!("caption: {caption}"));
|
||||||
lines.push(format!("media ({}):", media.len()));
|
lines.push(format!("media ({}):", media.len()));
|
||||||
for (i, item) in media.iter().enumerate() {
|
for (i, item) in media.iter().enumerate() {
|
||||||
let kind = match item {
|
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
|
||||||
|
// <blockquote expandable>; wrapping it again produced nested
|
||||||
|
// blockquotes, which the API rejects — /debug on any long post 400'd.
|
||||||
|
let quoted = "intro <blockquote expandable>long text</blockquote>";
|
||||||
|
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("<blockquote").count(),
|
||||||
|
1,
|
||||||
|
"no outer wrapper may be added: {report}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cap_text_cuts_on_a_char_boundary() {
|
fn cap_text_cuts_on_a_char_boundary() {
|
||||||
assert_eq!(cap_text("short".into(), 10), "short");
|
assert_eq!(cap_text("short".into(), 10), "short");
|
||||||
|
|||||||
Reference in New Issue
Block a user