test(host): HostFn id/name/params 一致性测试;refactor: 转义函数去重

一、先暴露问题:写 4 个一致性测试后发现——
- id 空间是**稀疏**的(10 个退役 id),不是连续的;测试按"每个已分配 id 都能还原"重写
- Access 变体只有隐式判别值,补 `= 212` 使之显式(避免重排时静默错位)
- 四个测试现在锁定:id→as_u16 往返、name→from_name 往返、名称唯一、
  required/optional 不重叠且无重复参数。审计提到的 from_name/name 漂移由此可被捕获。

二、转义去重
- urlencoding_encode 与 urlencoding_path 逐字相同 → 合并为 urlencoding_path(pub(crate))
- escape_js_string 两份:debug_page 的副本漏了 U+2028/2029 转义(真实缺陷)
  → 保留 html 的完整版并 pub(crate),debug_page 改为引用

cargo build 零警告;cargo test --release 609 passed / 0 failed(605 + 4 个新测试)。
This commit is contained in:
cflmy committed 2026-10-22 15:42:42 +08:00
1 parent a14a6e221d
commit 932403237a
3 files changed
+85 -31

No files matched your search

+1 -15
View File
@@ -3,6 +3,7 @@
//! Toolbar · Structure (breakpoints) · Variables / Breakpoints / Frame · Console
use std::path::{Path, PathBuf};
use super::html::escape_js_string;
use crate::view::html::{escape, nav_html, LinkMode};
use crate::view::render::{render_function_outline, render_module_structure_mode, StructureMode};
@@ -144,21 +145,6 @@ window.MARQDO_FILE_PATH = {path_js};
layout_debug(rel, &body)
}
fn escape_js_string(s: &str) -> String {
let mut out = String::from('"');
for c in s.chars() {
match c {
'\\' => out.push_str("\\\\"),
'"' => out.push_str("\\\""),
'\n' => out.push_str("\\n"),
'\r' => out.push_str("\\r"),
c if c.is_control() => out.push_str(&format!("\\u{:04x}", c as u32)),
c => out.push(c),
}
}
out.push('"');
out
}
fn layout_debug(title: &str, main: &str) -> String {
format!(