Model: a macro name with control characters is refused on every path

Only parse_macro refused a name holding a line break or other control
character. Macros that came from the macros field of a JSON workbook
were checked with check_limits alone, so a file could bring in a macro
named "a\nb" that macro.save and macro.rename would refuse. The check
now lives in Macro::check_limits, so every path applies it, and such a
macro is dropped with the usual warning when the file is opened.
This commit is contained in:
prxnvt
2026-10-22 02:26:32 -04:00
parent a4b4872602
commit 20d2a3b998
3 changed files with 18 additions and 4 deletions
+5 -1
View File
@@ -63,7 +63,8 @@ impl Macro {
count(&self.steps)
}
/// Checks the size limits ([`MAX_MACRO_STEPS`], [`MAX_MACRO_DEPTH`], name and text lengths).
/// Checks the size limits ([`MAX_MACRO_STEPS`], [`MAX_MACRO_DEPTH`], name and text lengths) and
/// that the name has no control characters.
pub fn check_limits(&self) -> Result<(), String> {
let name = self.name.trim();
if name.is_empty() {
@@ -72,6 +73,9 @@ impl Macro {
if name.chars().count() > MAX_MACRO_NAME {
return Err(format!("A macro name can be at most {MAX_MACRO_NAME} characters long."));
}
if name.chars().any(char::is_control) {
return Err("A macro name can't hold line breaks or other control characters.".into());
}
if self.description.chars().count() > MAX_MACRO_TEXT {
return Err(format!("A macro description can be at most {MAX_MACRO_TEXT} characters long."));
}