From 38dfb800e154d97b0e3e022cdce31d8429d914c6 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 20:03:45 -0800 Subject: [PATCH] Scripts: leave getIsFileOpen's path comparison as main has it The change to how getIsFileOpen compares paths on and off Windows goes in its own change, with its test. --- crates/engine/src/script/dom.rs | 13 ++++++------- crates/engine/src/tests/script_dom.rs | 8 -------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/crates/engine/src/script/dom.rs b/crates/engine/src/script/dom.rs index ee77772a08..a5bcbe015f 100644 --- a/crates/engine/src/script/dom.rs +++ b/crates/engine/src/script/dom.rs @@ -881,14 +881,13 @@ fn app_set_coords(h: &Host, a: &[Data]) -> Answer { Ok(Data::Undefined) } -/// A path as `getIsFileOpen` compares it. A Windows path (any path on Windows, or one with a drive -/// letter) has `\` and `/` alike and letters in one case; elsewhere a `\` is a character of a name. +/// A path as `getIsFileOpen` compares it: `\` and `/` alike, and on Windows paths (a drive letter +/// or a `\`) letters in one case. fn path_key(p: &str) -> String { - if cfg!(windows) || p.as_bytes().get(1) == Some(&b':') { - p.replace('\\', "/").trim_end_matches('/').to_lowercase() - } else { - p.trim_end_matches('/').to_string() - } + let windows = p.contains('\\') || p.as_bytes().get(1) == Some(&b':'); + let p = p.replace('\\', "/"); + let p = p.trim_end_matches('/').to_string(); + if windows { p.to_lowercase() } else { p } } /// `app.redraw()`: returns without changing anything. The app draws a frame between the run's diff --git a/crates/engine/src/tests/script_dom.rs b/crates/engine/src/tests/script_dom.rs index 1f0d231cf5..e87e5b5c51 100644 --- a/crates/engine/src/tests/script_dom.rs +++ b/crates/engine/src/tests/script_dom.rs @@ -1942,14 +1942,6 @@ fn get_is_file_open_cannot_probe_outside_script_scope() { let query = format!("vc.log(app.getIsFileOpen({p})); vc.log(app.getIsFileOpen({other}));"); let out = log(&mut s, &query); assert_eq!(out, vec![json!(true), json!(false)]); - // Outside Windows a `\` is a character of a name: the folder and the name joined by one name - // another file. - #[cfg(not(windows))] - { - let (dir, name) = (path.parent().unwrap().to_string_lossy(), path.file_name().unwrap().to_string_lossy()); - let joined = serde_json::to_string(&format!("{dir}\\{name}")).unwrap(); - assert_eq!(log(&mut s, &format!("vc.log(app.getIsFileOpen({joined}));")), vec![json!(false)], "{joined}"); - } // Read roots that leave out the document's file: the same path does not count. let elsewhere = fixture.join("elsewhere"); std::fs::create_dir_all(&elsewhere).unwrap();