From aaf27e1ec6129cfc73ed364cd4900c33833a1ebc Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Mon, 9 Nov 2026 00:57:54 +0100 Subject: [PATCH] Keep blank value row in single-column graph CSV round trip Found while testing crates/engine/src/cmd/graph/data.rs:51 (parse_csv); written by crates/doc/src/graph.rs:497 (GraphSpec::to_csv) Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/doc/src/graph.rs | 4 +++- crates/engine/src/cmd/graph/data.rs | 4 ++++ crates/engine/src/cmd/graph/tests.rs | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/doc/src/graph.rs b/crates/doc/src/graph.rs index 15f04ce15..72b066a06 100644 --- a/crates/doc/src/graph.rs +++ b/crates/doc/src/graph.rs @@ -525,7 +525,9 @@ impl GraphSpec { out.push_str(&field(self.categories.get(i).map(String::as_str).unwrap_or_default(), true)); out.push(','); } - out.push_str(&r.iter().map(|v| v.map(|v| v.to_string()).unwrap_or_default()).collect::>().join(",")); + let line = r.iter().map(|v| v.map(|v| v.to_string()).unwrap_or_default()).collect::>().join(","); + // A lone blank value would be an empty line, which readers skip; a quoted empty field keeps the row. + out.push_str(if line.is_empty() && !labelled { "\"\"" } else { &line }); out.push('\n'); } out diff --git a/crates/engine/src/cmd/graph/data.rs b/crates/engine/src/cmd/graph/data.rs index 3e2122349..f4eb3ef83 100644 --- a/crates/engine/src/cmd/graph/data.rs +++ b/crates/engine/src/cmd/graph/data.rs @@ -50,6 +50,10 @@ pub(super) fn parse_csv(csv: &str) -> (Vec, Vec, Vec 1 { tabs } else { split_unquoted(l, ',') }; parts.into_iter().map(cell).collect() diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 650a4275a..6cb36431e 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -4210,3 +4210,12 @@ fn character_formats_are_kept_and_bigger_labels_space_out() { fn csv_leading_byte_order_mark_is_ignored() { assert_eq!(super::parse_csv("\u{feff}1,2\n3,4"), super::parse_csv("1,2\n3,4")); } + +#[test] +fn csv_round_trip_keeps_blank_row_in_single_column_graph() { + let mut g = GraphSpec::default(); + g.set_cells(vec![vec![Some(1.0)], vec![None], vec![Some(3.0)]]); + let (_, c, r) = super::parse_csv(&g.to_csv()); + assert!(c.is_empty()); + assert_eq!(r, g.cells()); +}