(7ac39e3) Fix byte-slice panics in id shortening and date formatting
Three places sliced strings by byte offset on values that come from a filename or a file field, neither of which is validated. The disambiguation list took &short_id[..7], so two tickets whose names were shorter than that aborted the process while printing the options. collect_ticket_items guarded on length but still cut at byte 7, so a multibyte character straddling the cut panicked. format_created_at read four fixed offsets after a length check that a multibyte value passes. Add short_id, which counts characters, and use it in both display paths. Parse the timestamp with chrono instead of slicing, dropping the column when the value will not parse. The format string it writes and the one it reads are now the same constant, so they cannot drift. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
8ff64614fc
commit
c675da1d2a
@@ -174,3 +174,45 @@ fn ls_displays_owner_and_due() {
|
||||
assert!(stdout.contains("alice"));
|
||||
assert!(stdout.contains("2026-12-31"));
|
||||
}
|
||||
|
||||
/// Both the abbreviated id and the created-at column used to slice by byte
|
||||
/// offset, so either a short name or a multibyte character panicked.
|
||||
#[test]
|
||||
fn ls_handles_short_and_non_ascii_filenames() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
|
||||
for filename in ["ab.md", "émigré-ticket.md", "日本語.md"] {
|
||||
fs::write(
|
||||
worklane.join("backlog").join(filename),
|
||||
"# Odd Name\n\n## Metadata\n\n- **Owner**: alice\n- **Status**: backlog\n",
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(&temp.path()).arg("ls").arg("backlog").assert().success();
|
||||
|
||||
let stdout = get_stdout(&mut cmd);
|
||||
assert_eq!(stdout.matches("Odd Name").count(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ls_survives_a_malformed_created_at() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
|
||||
fs::write(
|
||||
worklane.join("backlog").join("00000000-0000-0000-0000-000000000009_bad-date.md"),
|
||||
"# Bad Date\n\n## Metadata\n\n- **Created At**: 日本語日本語日本語\n- **Status**: backlog\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(&temp.path()).arg("ls").arg("backlog").assert().success();
|
||||
|
||||
let stdout = get_stdout(&mut cmd);
|
||||
assert!(stdout.contains("Bad Date"));
|
||||
// Unparseable, so the timestamp column is dropped rather than printed raw
|
||||
assert!(!stdout.contains("日本語"));
|
||||
}
|
||||
|
||||
@@ -265,6 +265,56 @@ fn show_asks_for_disambiguation_when_multiple_matches() {
|
||||
assert!(stdout.contains("Use the displayed ID"));
|
||||
}
|
||||
|
||||
/// Filenames shorter than the displayed id width used to panic while printing
|
||||
/// the disambiguation list.
|
||||
#[test]
|
||||
fn show_disambiguates_tickets_with_short_filenames() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
|
||||
fs::write(
|
||||
worklane.join("backlog").join("abc.md"),
|
||||
"# Short One\n\n## Metadata\n\n- **ID**: 1234\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
worklane.join("backlog").join("xy.md"),
|
||||
"# Short Two\n\n## Metadata\n\n- **ID**: 5678\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(&temp.path()).arg("show").arg("short");
|
||||
|
||||
let stdout = get_stdout(&mut cmd);
|
||||
assert!(stdout.contains("Multiple tickets found"));
|
||||
assert!(stdout.contains("Short One"));
|
||||
assert!(stdout.contains("Short Two"));
|
||||
}
|
||||
|
||||
/// A multibyte character straddling the cut used to panic.
|
||||
#[test]
|
||||
fn show_disambiguates_tickets_with_non_ascii_filenames() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
|
||||
for (filename, title) in [("émigré-un.md", "Accented One"), ("日本語-二.md", "Accented Two")] {
|
||||
fs::write(
|
||||
worklane.join("backlog").join(filename),
|
||||
format!("# {}\n\n## Metadata\n\n- **ID**: 1234\n", title),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(&temp.path()).arg("show").arg("accented");
|
||||
|
||||
let stdout = get_stdout(&mut cmd);
|
||||
assert!(stdout.contains("Multiple tickets found"));
|
||||
assert!(stdout.contains("Accented One"));
|
||||
assert!(stdout.contains("Accented Two"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn show_searches_across_all_statuses() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user