From 556d44d47a94c6be320ce42f99064bfed970ea34 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Sat, 31 Oct 2026 15:37:22 +0100 Subject: [PATCH] Reject '+' sign in comment parse_link thread ids (#1740) Found while testing crates/engine/src/cmd/comment.rs:55 (parse_link) Co-authored-by: Claude Haiku 5.5 --- crates/engine/src/cmd/comment.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/comment.rs b/crates/engine/src/cmd/comment.rs index cf675d0fc..c2eb69b12 100644 --- a/crates/engine/src/cmd/comment.rs +++ b/crates/engine/src/cmd/comment.rs @@ -52,7 +52,12 @@ pub fn link(id: u64) -> String { /// The thread id in a link (or a bare id). pub fn parse_link(s: &str) -> Option { let s = s.trim(); - s.strip_prefix(LINK_PREFIX).unwrap_or(s).trim_end_matches('/').parse().ok() + let s = s.strip_prefix(LINK_PREFIX).unwrap_or(s).trim_end_matches('/'); + // Digits only: `u64::parse` would also accept a leading '+'. + if !s.bytes().all(|b| b.is_ascii_digit()) { + return None; + } + s.parse().ok() } /// Which threads a list shows. @@ -997,6 +1002,15 @@ mod tests { use crate::Session; + #[test] + fn parse_link_rejects_sign() { + assert_eq!(super::parse_link("+5"), None); + assert_eq!(super::parse_link("figcraft://comment/+5"), None); + assert_eq!(super::parse_link(""), None); + assert_eq!(super::parse_link("5"), Some(5)); + assert_eq!(super::parse_link("figcraft://comment/5/"), Some(5)); + } + #[test] fn comment_thread_lifecycle_and_anchoring() { let mut s = Session::new();