From bbfdd44ebf83fc5f1918cb093253d87f3c1b1d1a Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sun, 1 Nov 2026 00:30:26 -0500 Subject: [PATCH] fix(id): trim the separator after /document and /input (#1946) Both commands rejected a second space after the verb while their siblings (/records, /documents, /logs) trim the separator: /document required the trimmed name to equal the raw rest, and /input validated the untrimmed hex. Trim both; a name with interior spaces is still one name, and bad hex still answers with usage. New tests pin the two-space forms. --- pkgs/id/src/world_line.rs | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/pkgs/id/src/world_line.rs b/pkgs/id/src/world_line.rs index d31566cdfd..15c193f446 100644 --- a/pkgs/id/src/world_line.rs +++ b/pkgs/id/src/world_line.rs @@ -75,8 +75,11 @@ pub fn parse_line(line: &str) -> Option { return Some(WorldLine::Message("usage: /document ".to_owned())); } if let Some(rest) = line.strip_prefix("/document ") { + // The separator is whitespace, not exactly one space: siblings + // (/records, /documents, /logs) trim theirs, and a name with + // interior spaces ("my file.txt") is still one name. let name = rest.trim(); - if !name.is_empty() && name == rest { + if !name.is_empty() { return Some(WorldLine::Document(name.to_owned())); } return Some(WorldLine::Message("usage: /document ".to_owned())); @@ -97,6 +100,7 @@ pub fn parse_line(line: &str) -> Option { return Some(WorldLine::Message("usage: /input ".to_owned())); } if let Some(hex) = line.strip_prefix("/input ") { + let hex = hex.trim(); if !hex.is_empty() && hex.len() % 2 == 0 && hex.bytes().all(|b| b.is_ascii_hexdigit()) { return Some(WorldLine::Input(hex.to_ascii_lowercase())); } @@ -164,6 +168,34 @@ mod tests { ); } + #[test] + fn extra_separator_whitespace_still_parses() { + // #1946: the separator after /document and /input is whitespace, + // not exactly one space — the sibling commands already trim. + assert_eq!( + parse_line("/document report.txt"), + Some(WorldLine::Document("report.txt".into())) + ); + assert_eq!( + parse_line("/input ab"), + Some(WorldLine::Input("ab".into())) + ); + // A name with interior spaces is still one name. + assert_eq!( + parse_line("/document my file.txt"), + Some(WorldLine::Document("my file.txt".into())) + ); + // Extra separator whitespace does not rescue a bad argument. + assert_eq!( + parse_line("/input zz"), + Some(WorldLine::Message("usage: /input ".into())) + ); + assert_eq!( + parse_line("/input abc"), + Some(WorldLine::Message("usage: /input ".into())) + ); + } + #[test] fn glued_and_bare_verbs_do_not_parse_as_commands() { // #1507: every verb needs its boundary — exact, or the verb, a space,