From 99ffa0ebd81f8d766e8d49e169e9aa4fbbd40a2e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 16:59:34 -0800 Subject: [PATCH] Plug-ins: a command's menu.after is checked before its spaces are trimmed A menu.after value with a control character at either end, or longer than 64 characters before its spaces are trimmed, is refused with the same error as other wrongly shaped values. --- crates/plugins/src/manifest.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/plugins/src/manifest.rs b/crates/plugins/src/manifest.rs index 80906ceac6..b9e36cfd24 100644 --- a/crates/plugins/src/manifest.rs +++ b/crates/plugins/src/manifest.rs @@ -90,11 +90,11 @@ impl MenuPlace { let after = match o.get("after") { None => None, Some(Value::String(s)) => { - let s = s.trim(); - if s.is_empty() || s.chars().count() > 64 || s.chars().any(char::is_control) { + let trimmed = s.trim(); + if trimmed.is_empty() || s.chars().count() > 64 || s.chars().any(char::is_control) { return Err(format!("`{key}` must be 1-64 printable characters")); } - Some(s.to_string()) + Some(trimmed.to_string()) } Some(_) => return Err(format!("`{key}` must be a string")), }; @@ -1442,6 +1442,7 @@ mod tests { } let long = format!(r#"{{"path":["Select"],"after":"{}"}}"#, "x".repeat(65)); + let padded = format!(r#"{{"path":["Select"],"after":" {} "}}"#, "x".repeat(64)); for (menu, says) in [ (r#"{"path":["File"]}"#, "`menu.path` must be one of"), (r#"{"path":["Help"]}"#, "`menu.path` must be one of"), @@ -1461,7 +1462,9 @@ mod tests { (r#"{"path":["Select"],"after":null}"#, "`menu.after` must be a string"), (r#"{"path":["Select"],"after":" "}"#, "`menu.after` must be 1-64 printable characters"), (r#"{"path":["Select"],"after":"In\u0007verse"}"#, "`menu.after` must be 1-64 printable characters"), + (r#"{"path":["Select"],"after":"\nInverse\n"}"#, "`menu.after` must be 1-64 printable characters"), (long.as_str(), "`menu.after` must be 1-64 printable characters"), + (padded.as_str(), "`menu.after` must be 1-64 printable characters"), (r#"{"path":["Select"]},"menu":{"path":["Edit"]}"#, "duplicate field `menu`"), ] { let e = Manifest::parse(with(2, menu).as_bytes()).unwrap_err().to_string();