From 16caa7dd9e83ffb7c690598dbf5b8af8c96d27d1 Mon Sep 17 00:00:00 2001 From: xfy Date: Tue, 14 Jul 2026 14:29:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(comments):=20=E7=BB=9F=E4=B8=80=20escape=5F?= =?UTF-8?q?html=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81=E5=9D=97?= =?UTF-8?q?=E5=8D=95=E5=BC=95=E5=8F=B7=E6=9C=AA=E8=BD=AC=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit comments/markdown.rs 的本地 html_escape 只转义 4 个字符(漏单引号), 与规范实现 utils::html::escape_html(5 字符,'→')不一致。 删除本地副本,改用 crate::utils::html::escape_html。评论代码块里的 单引号现在会被正确转义,与其他上下文的转义行为统一。 --- src/api/comments/markdown.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/api/comments/markdown.rs b/src/api/comments/markdown.rs index 5bb0da2..4e14f6c 100644 --- a/src/api/comments/markdown.rs +++ b/src/api/comments/markdown.rs @@ -5,15 +5,6 @@ #![allow(clippy::unused_unit, deprecated)] -/// 转义 HTML 特殊字符,用于无语言信息的代码块。 -#[cfg(feature = "server")] -fn html_escape(s: &str) -> String { - s.replace('&', "&") - .replace('<', "<") - .replace('>', ">") - .replace('"', """) -} - /// 清洗评论 HTML,移除危险标签与属性。 /// /// 实际委托给 `crate::api::sanitizer::clean_comment_html` 实现。 @@ -67,7 +58,7 @@ pub fn render_comment_markdown(md: &str) -> String { crate::highlight::server::highlight_code(&code_buffer, Some(lang)); format!("
{}
", highlighted) } else { - format!("
{}
", html_escape(&code_buffer)) + format!("
{}
", crate::utils::html::escape_html(&code_buffer)) }; events.push(Event::Html(html.into())); in_codeblock = false;