Reject '+' sign in NodeId::from_str

Found while testing crates/doc/src/lib.rs:64-71 (impl FromStr for NodeId), reached through crates/engine/src/automation/params.rs:78 (id_of)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NetterSilver
2026-10-27 08:35:02 +00:00
co-authored by Claude Haiku 5.5
parent 43af145a12
commit f1264cf13e
2 changed files with 12 additions and 0 deletions
+8
View File
@@ -110,3 +110,11 @@ fn the_highest_space_counts_every_kind_of_id() {
assert_eq!(id_space("S:99999999999999999999999", "S:"), 0, "too big for a number");
assert_eq!(mode_number("1:0"), None);
}
#[test]
fn nodeid_rejects_plus_sign() {
assert!("+12".parse::<crate::NodeId>().is_err());
assert!("0:+12".parse::<crate::NodeId>().is_err());
assert_eq!("12".parse::<crate::NodeId>(), Ok(crate::NodeId(12)));
assert_eq!("0:12".parse::<crate::NodeId>(), Ok(crate::NodeId(12)));
}
+4
View File
@@ -67,6 +67,10 @@ impl std::str::FromStr for NodeId {
// Accept "12" and Figma-style "0:12".
let t = s.trim();
let t = t.rsplit(':').next().unwrap_or(t);
if t.starts_with('+') {
// `u64::parse` accepts a leading '+'; ids are digits only.
return "-".parse::<u64>().map(NodeId);
}
t.parse::<u64>().map(NodeId)
}
}