fix(comments): 统一 escape_html,修复代码块单引号未转义

comments/markdown.rs 的本地 html_escape 只转义 4 个字符(漏单引号),
与规范实现 utils::html::escape_html(5 字符,'→')不一致。

删除本地副本,改用 crate::utils::html::escape_html。评论代码块里的
单引号现在会被正确转义,与其他上下文的转义行为统一。
This commit is contained in:
xfy 2026-07-14 14:29:53 +08:00
parent b39afbb616
commit 16caa7dd9e

View File

@ -5,15 +5,6 @@
#![allow(clippy::unused_unit, deprecated)] #![allow(clippy::unused_unit, deprecated)]
/// 转义 HTML 特殊字符,用于无语言信息的代码块。
#[cfg(feature = "server")]
fn html_escape(s: &str) -> String {
s.replace('&', "&")
.replace('<', "&lt;")
.replace('>', "&gt;")
.replace('"', "&quot;")
}
/// 清洗评论 HTML移除危险标签与属性。 /// 清洗评论 HTML移除危险标签与属性。
/// ///
/// 实际委托给 `crate::api::sanitizer::clean_comment_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)); crate::highlight::server::highlight_code(&code_buffer, Some(lang));
format!("<pre><code>{}</code></pre>", highlighted) format!("<pre><code>{}</code></pre>", highlighted)
} else { } else {
format!("<pre><code>{}</code></pre>", html_escape(&code_buffer)) format!("<pre><code>{}</code></pre>", crate::utils::html::escape_html(&code_buffer))
}; };
events.push(Event::Html(html.into())); events.push(Event::Html(html.into()));
in_codeblock = false; in_codeblock = false;