diff --git a/Cargo.lock b/Cargo.lock index 155e892..e5da970 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1503,7 +1503,7 @@ dependencies = [ [[package]] name = "worklane" -version = "0.32.4" +version = "0.32.5" dependencies = [ "anyhow", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index 162a98e..7b88d4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "worklane" -version = "0.32.4" +version = "0.32.5" edition = "2024" [dependencies] diff --git a/src/command.rs b/src/command.rs index 8318938..782c83c 100644 --- a/src/command.rs +++ b/src/command.rs @@ -162,22 +162,35 @@ fn tag_value(raw: &str) -> Result { Ok(value.to_string()) } -/// Reject an annotation line that would be read back as a tag of its own. +/// Reject an annotation the vocabulary file or the listing cannot carry. /// /// The vocabulary is one heading per tag with its prose under it, so a line of prose /// starting with the section marker would split the annotation and declare whatever -/// followed. Refused at parse time, where nothing has been written, rather than escaped on -/// the way in: an annotation is prose, and quietly rewriting prose is worse than asking for -/// a different line. +/// followed. A tab anywhere in the value is refused for the listing's sake rather than the +/// file's: `tags ls` prints one tag, its count and the annotation's opening line as three +/// tab-separated fields, so an annotation holding a tab reads as the start of a fourth +/// field and everything after it is silently gone. +/// +/// Both are refused at parse time, where nothing has been written, rather than escaped on +/// the way in: an annotation is prose, and quietly rewriting prose is worse than asking +/// for a different line. fn annotation_line(raw: &str) -> Result { - match raw.lines().any(|line| line.starts_with(crate::tag::SECTION)) { - true => Err(format!( + if raw.lines().any(|line| line.starts_with(crate::tag::SECTION)) { + return Err(format!( "an annotation line cannot start with '{}', which is how the vocabulary file \ starts a tag", crate::tag::SECTION - )), - false => Ok(raw.to_string()), + )); } + + if raw.contains('\t') { + return Err( + "an annotation cannot contain a tab, which is how `tags ls` separates its fields" + .to_string(), + ); + } + + Ok(raw.to_string()) } /// What `--actor` says on every command that writes a history entry. diff --git a/tests/cmd_tags.rs b/tests/cmd_tags.rs index 43e20c7..eb8f41e 100644 --- a/tests/cmd_tags.rs +++ b/tests/cmd_tags.rs @@ -316,6 +316,71 @@ fn an_annotation_that_would_read_as_a_heading_is_refused() { assert!(!temp.path().join(".worklane").join("tags.md").exists()); } +/// A tab anywhere in an annotation is refused by `tags add`, because the listing's fields +/// are tab separated: past the first tab everything after it reads as a fourth field. The +/// refusal says why, and nothing is written — the value parser refuses before the handler +/// runs, so not even a placeholder file is left behind. +#[test] +fn an_annotation_carrying_a_tab_is_refused_by_tags_add() { + let temp = TempDir::new().unwrap(); + setup_worklane(&temp); + + let out = run(&temp, &["tags", "add", "bug", "-a", "Something\twrong."]); + let stderr = String::from_utf8_lossy(&out.stderr); + assert!(!out.status.success(), "{stderr}"); + assert!( + stderr.contains("tab") && stderr.contains("separates its fields"), + "{stderr}" + ); + assert!(!temp.path().join(".worklane").join("tags.md").exists()); + + // No staged write survived either, so the directory holds only the status folders. + let left: Vec<_> = fs::read_dir(temp.path().join(".worklane")) + .unwrap() + .map(|e| e.unwrap().file_name()) + .collect(); + assert_eq!(left.len(), 4, "{left:?}"); +} + +/// The same value is refused by `tags set`, and the declaration that is already there is +/// untouched. +#[test] +fn an_annotation_carrying_a_tab_is_refused_by_tags_set() { + let temp = TempDir::new().unwrap(); + setup_worklane(&temp); + + run(&temp, &["tags", "add", "bug", "-a", "Something wrong."]); + let before = vocabulary(&temp); + + let out = run(&temp, &["tags", "set", "bug", "-a", "Now\twith a tab."]); + assert!(!out.status.success(), "{}", String::from_utf8_lossy(&out.stderr)); + assert_eq!(vocabulary(&temp), before); +} + +/// Ordinary prose is unaffected, paragraphs included: the refusal is for the tab alone, +/// which is what keeps it from standing in front of the command's whole purpose. +#[test] +fn an_annotation_without_a_tab_is_taken_whatever_its_shape() { + let temp = TempDir::new().unwrap(); + setup_worklane(&temp); + + run( + &temp, + &[ + "tags", + "add", + "bug", + "-a", + "A defect.", + "-a", + "", + "-a", + "--plan is prose", + ], + ); + assert_eq!(declared(&temp, "bug").as_deref(), Some("A defect.\n\n--plan is prose")); +} + /// The file is made on demand, the way `campaign add` makes the campaigns directory: a board /// that predates the vocabulary must not need `worklane init` run over it. #[test]