MCP: a readable library id written with LOADED/ keeps its text on Windows

The loaded/ prefix is matched in any case where the ids and paths are.
This commit is contained in:
dotCooCoo
2026-11-11 17:31:25 -08:00
parent 2d2e8fa53f
commit 386c444ff4
2 changed files with 7 additions and 1 deletions
+2 -1
View File
@@ -734,8 +734,9 @@ fn begins_known_id(text: &str, at: usize, end: usize, r: &Rewrite) -> bool {
let rest = &text[at..];
let same = |a: &str, b: &str| if r.fold { a.eq_ignore_ascii_case(b) } else { a == b };
let dotted = |id: &str| id.split(['/', '\\']).any(|part| part == "." || part == "..");
let prefixed = rest.get(.."loaded/".len()).is_some_and(|head| same(head, "loaded/"));
r.hiding.readable.iter().filter(|known| !dotted(known)).any(|known| {
let id = if rest.starts_with("loaded/") { known.as_str() } else { known.strip_prefix("loaded/").unwrap_or(known) };
let id = if prefixed { known.as_str() } else { known.strip_prefix("loaded/").unwrap_or(known) };
id.len() > end - at && rest.get(..id.len()).is_some_and(|head| same(head, id)) && !continues_path(&rest[id.len()..])
})
}
+5
View File
@@ -105,6 +105,11 @@ fn a_reply_hides_a_path_in_any_case_and_escaped() {
let mut reply = json!({"error": "x /libs/B.svg y /libs/b.svg z /LIBS/b.svg"});
super::replace_in_value(&mut reply, &super::Rewrite { pairs: super::hidden_text(&two.hidden), hiding: &two, fold: true });
assert_eq!(reply["error"], "x B.svg y b.svg z b.svg", "{reply}");
// A readable id that begins with a hidden one stays whole in any case, `loaded/` included.
let nested = hiding(&[("loaded//libs/in", "loaded/in")], &["loaded//libs/in/a.svg"]);
let mut reply = json!({"error": "LOADED//LIBS/IN/A.SVG"});
super::replace_in_value(&mut reply, &super::Rewrite { pairs: super::hidden_text(&nested.hidden), hiding: &nested, fold: true });
assert_eq!(reply["error"], "LOADED//LIBS/IN/A.SVG", "{reply}");
let mut reply = json!({"error": "file:///C:/Libs/My%20Swatches/b.svg"});
hide_under_a_root("escaped", &mut reply, &hidden);
assert_eq!(reply["error"], "file:///b.svg", "{reply}");