Engine: only hidden names are read as macro storage

A visible workbook-scope name such as `_gc_macro_0_0` matched the storage key and was read as a
macro and removed when the workbook opened. Macro storage is written hidden, so only hidden names
are read back; a person's own name of that shape stays a name.
This commit is contained in:
prxnvt
2026-10-22 02:26:32 -04:00
parent 3c74dfcbb0
commit 6312c7cb40
2 changed files with 16 additions and 1 deletions
+3 -1
View File
@@ -177,7 +177,9 @@ pub fn load(wb: &mut Workbook) -> Vec<String> {
/// The item key (`macro_<n>`, lower-cased) of a hidden macro name, and `n` when it is a number.
fn macro_item(n: &DefinedName) -> Option<(String, Option<u64>)> {
let key = stash::item_key(&n.name).filter(|k| n.scope.is_none() && k.starts_with(MACRO_KEY))?;
// Only a hidden workbook-scope name is macro storage: a person's own visible name that
// happens to look like one stays a name.
let key = stash::item_key(&n.name).filter(|k| n.hidden && n.scope.is_none() && k.starts_with(MACRO_KEY))?;
let i = key.strip_prefix(MACRO_KEY).and_then(|i| i.parse().ok());
Some((key, i))
}
+13
View File
@@ -127,6 +127,19 @@ fn hidden(name: &str, text: &str) -> DefinedName {
DefinedName { name: name.into(), scope: None, formula: format!("\"{}\"", text.replace('"', "\"\"")), comment: String::new(), hidden: true }
}
#[test]
fn a_visible_name_that_looks_like_macro_storage_is_left_alone() {
// Macro storage is hidden workbook-scope names; a visible `_gc_macro_0_0` someone defined
// is neither read as a macro nor removed when the workbook opens.
let mut wb = Workbook::new();
let name = DefinedName { hidden: false, ..hidden("_gc_macro_0_0", "x") };
wb.names.push(name.clone());
let warnings = load(&mut wb);
assert!(warnings.is_empty(), "{warnings:?}");
assert!(wb.macros.is_empty());
assert_eq!(wb.names, vec![name]);
}
#[test]
fn scripts_and_vba_stay_as_they_are() {
// Automate scripts keep their own storage, and a VBA project is carried through unchanged.