mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-03 00:41:56 -06:00
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:
@@ -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."));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user