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();