From b3430b7f825a832fe09c8b85459d8ea9440d7df5 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 04:45:41 -0800 Subject: [PATCH] Script File Access: no row for a grant with an empty script or path script.grants lists a kept grant whose script or path is an empty string, but script.grants.revoke does not take an empty path, so its Revoke button could not remove it. Such a grant now has no row. --- .../ui-egui/src/prefs_dialog/script_access.rs | 6 +++++- crates/ui-egui/src/prefs_dialog/tests.rs | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/prefs_dialog/script_access.rs b/crates/ui-egui/src/prefs_dialog/script_access.rs index e8e70ec1eb..bdf4b128f5 100644 --- a/crates/ui-egui/src/prefs_dialog/script_access.rs +++ b/crates/ui-egui/src/prefs_dialog/script_access.rs @@ -77,7 +77,8 @@ pub(super) fn load(app: &mut VectorcraftApp) -> Option { /// The rows for the grants `grants` lists: one for each script and path, sorted by script and then by path, with the /// widest access any kept version of the pair has (`folder`, then `write`, then `read`) and how many versions are -/// kept. A grant without a script or a path is left out. +/// kept. A grant without a script or a path, or with an empty one, which `script.grants.revoke` does not take, is +/// left out. fn rows(grants: &Value) -> Vec { let rank = |access: &str| match access { "folder" => 2, @@ -87,6 +88,9 @@ fn rows(grants: &Value) -> Vec { let mut pairs: BTreeMap<(&str, &str), (&'static str, usize)> = BTreeMap::new(); for g in grants.as_array().into_iter().flatten() { let (Some(script), Some(path)) = (g["script"].as_str(), g["path"].as_str()) else { continue }; + if script.is_empty() || path.is_empty() { + continue; + } let access = if g["folder"] == true { "folder" } else if g["write"] == true { diff --git a/crates/ui-egui/src/prefs_dialog/tests.rs b/crates/ui-egui/src/prefs_dialog/tests.rs index 02c9913b43..c148173378 100644 --- a/crates/ui-egui/src/prefs_dialog/tests.rs +++ b/crates/ui-egui/src/prefs_dialog/tests.rs @@ -833,6 +833,25 @@ fn script_file_access_shows_none_and_a_revoke_of_a_removed_row() { assert!(access_texts(&mut web).is_empty()); } +/// A kept grant with an empty script or path, which `script.grants` lists and `script.grants.revoke` does not take, +/// has no row. +#[test] +fn script_file_access_leaves_out_a_grant_with_an_empty_script_or_path() { + let dir = std::env::temp_dir().join("vc-ui-prefs-grants-nowhere"); + let (script, path) = (dir.join("a.jsx"), dir.join("out.txt")); + let grants = json!([ + grant(&script, &path, "1", false, false), + grant(&script, "".as_ref(), "1", false, false), + grant("".as_ref(), &path, "1", false, false) + ]); + let (mut a, store) = app_with_grants("grants-empty", grants); + assert_eq!(a.session.execute("script.grants", &json!({})).unwrap()["grants"].as_array().map(Vec::len), Some(3)); + open(&mut a, Some("General")); + let row = (script.to_string_lossy().into_owned(), path.to_string_lossy().into_owned(), "read".to_string(), 1); + assert_eq!(access_rows(&a), [row]); + let _ = std::fs::remove_dir_all(store.parent().unwrap()); +} + /// Preferences opened with a read root in force shows a script and a path outside it by their file /// names alone, as `script.grants` lists them, and `ui.inspect` names them the same way; Revoke /// still removes that pair's kept grants, both with the root in force and without it.