diff --git a/pkgs/id/src/world_line.rs b/pkgs/id/src/world_line.rs index a692074c78..26e29dadee 100644 --- a/pkgs/id/src/world_line.rs +++ b/pkgs/id/src/world_line.rs @@ -41,12 +41,20 @@ pub enum WorldLine { /// /// An empty line returns `None`. Any other line that does not start with `/` /// is chat. Unknown `/` commands become [`WorldLine::Message`]. +/// +/// The verb boundary is uniform for every verb: the verb itself, or the +/// verb followed by an ASCII space and its argument. A tab is not a +/// separator (#4492) — `/helpme` and `/logs5` are both unknown +/// commands — while repeated spaces still parse because the argument +/// remainder is trimmed. #[must_use] pub fn parse_line(line: &str) -> Option { if line.is_empty() { return None; } - match line.split_whitespace().next() { + // Split on the ASCII space only, not on whitespace: the bare verbs use + // the same literal-space boundary as the argument verbs below. + match line.split(' ').next() { Some("/help") => return Some(WorldLine::Help), Some("/quit") => return Some(WorldLine::Quit), Some("/stats") => return Some(WorldLine::Stats), @@ -75,9 +83,10 @@ 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 + // The separator is ASCII spaces, not exactly one space: siblings // (/records, /documents, /logs) trim theirs, and a name with - // interior spaces ("my file.txt") is still one name. + // interior spaces ("my file.txt") is still one name. A tab is not + // a separator — the verb boundary is a literal space (#4492). let name = rest.trim(); if !name.is_empty() { return Some(WorldLine::Document(name.to_owned())); @@ -186,8 +195,8 @@ 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. + // #1946: the separator after /document and /input is one or more + // ASCII spaces, not exactly one space — siblings trim theirs. assert_eq!( parse_line("/document report.txt"), Some(WorldLine::Document("report.txt".into())) @@ -240,6 +249,40 @@ mod tests { ); } + #[test] + fn test_tab_is_not_a_verb_boundary_for_any_verb_class() { + // #4492: one boundary rule — a tab separates nothing, for bare + // verbs exactly as for argument verbs (#1507 pinned /logs5). + for line in ["/help\tme", "/stats\tall", "/quit\tnow", "/caps\tlist"] { + assert_eq!( + parse_line(line), + Some(WorldLine::Message("unknown command; type /help".into())), + "{line:?}" + ); + } + for line in ["/logs\t5", "/records\tfoo", "/documents\tfoo", "/document\treport.txt", "/input\tab"] { + assert_eq!( + parse_line(line), + Some(WorldLine::Message("unknown command; type /help".into())), + "{line:?}" + ); + } + } + + #[test] + fn test_space_boundary_still_parses_for_bare_and_argument_verbs() { + assert_eq!(parse_line("/help me"), Some(WorldLine::Help)); + assert_eq!(parse_line("/help me"), Some(WorldLine::Help)); + assert_eq!( + parse_line("/logs 5"), + Some(WorldLine::Logs { seconds: Some(5) }) + ); + assert_eq!( + parse_line("/logs 5"), + Some(WorldLine::Logs { seconds: Some(5) }) + ); + } + #[test] fn unknown_and_malformed_commands_become_messages() { assert_eq!(