Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cac21a94f5 |
Generated
+1
-1
@@ -1503,7 +1503,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "worklane"
|
name = "worklane"
|
||||||
version = "0.32.4"
|
version = "0.32.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"assert_cmd",
|
"assert_cmd",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "worklane"
|
name = "worklane"
|
||||||
version = "0.32.4"
|
version = "0.32.5"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
+21
-8
@@ -162,22 +162,35 @@ fn tag_value(raw: &str) -> Result<String, String> {
|
|||||||
Ok(value.to_string())
|
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
|
/// 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
|
/// 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
|
/// followed. A tab anywhere in the value is refused for the listing's sake rather than the
|
||||||
/// the way in: an annotation is prose, and quietly rewriting prose is worse than asking for
|
/// file's: `tags ls` prints one tag, its count and the annotation's opening line as three
|
||||||
/// a different line.
|
/// 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<String, String> {
|
fn annotation_line(raw: &str) -> Result<String, String> {
|
||||||
match raw.lines().any(|line| line.starts_with(crate::tag::SECTION)) {
|
if raw.lines().any(|line| line.starts_with(crate::tag::SECTION)) {
|
||||||
true => Err(format!(
|
return Err(format!(
|
||||||
"an annotation line cannot start with '{}', which is how the vocabulary file \
|
"an annotation line cannot start with '{}', which is how the vocabulary file \
|
||||||
starts a tag",
|
starts a tag",
|
||||||
crate::tag::SECTION
|
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.
|
/// What `--actor` says on every command that writes a history entry.
|
||||||
|
|||||||
@@ -316,6 +316,71 @@ fn an_annotation_that_would_read_as_a_heading_is_refused() {
|
|||||||
assert!(!temp.path().join(".worklane").join("tags.md").exists());
|
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
|
/// 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.
|
/// that predates the vocabulary must not need `worklane init` run over it.
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user