From ea6bb98fc7e84e9bdcf9f5823ccb6b0a6b7699c1 Mon Sep 17 00:00:00 2001 From: MarekSpodBiedry <73122968+MarekSpodBiedry@users.noreply.github.com> Date: Mon, 12 Oct 2026 08:28:50 +0200 Subject: [PATCH] fix(xlsx): keep leading and trailing whitespace in document properties on reopen (#554) --- crates/xlsx/src/read.rs | 4 ++-- crates/xlsx/src/tests/roundtrip.rs | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/xlsx/src/read.rs b/crates/xlsx/src/read.rs index a25444d88..a83432bd2 100644 --- a/crates/xlsx/src/read.rs +++ b/crates/xlsx/src/read.rs @@ -301,7 +301,7 @@ pub fn read_xlsx(bytes: &[u8]) -> Result<(Workbook, ReadReport), IoError> { if let Some(r) = find_rel(&root_rels, "core-properties").cloned() && let Ok(Some(x)) = cx.pkg.read_xml(&r.target) { - let get = |n: &str| x.child(n).map(|e| e.text.trim().to_string()).unwrap_or_default(); + let get = |n: &str| x.child(n).map(|e| e.text.clone()).unwrap_or_default(); wb.props.title = get("title"); wb.props.subject = get("subject"); wb.props.author = get("creator"); @@ -311,7 +311,7 @@ pub fn read_xlsx(bytes: &[u8]) -> Result<(Workbook, ReadReport), IoError> { if let Some(r) = find_rel(&root_rels, "extended-properties").cloned() && let Ok(Some(x)) = cx.pkg.read_xml(&r.target) { - wb.props.company = x.child("Company").map(|e| e.text.trim().to_string()).unwrap_or_default(); + wb.props.company = x.child("Company").map(|e| e.text.clone()).unwrap_or_default(); } // A VBA project is carried through unchanged: GridCraft never runs macros, but preserving the diff --git a/crates/xlsx/src/tests/roundtrip.rs b/crates/xlsx/src/tests/roundtrip.rs index 960157254..b800e299a 100644 --- a/crates/xlsx/src/tests/roundtrip.rs +++ b/crates/xlsx/src/tests/roundtrip.rs @@ -1014,3 +1014,18 @@ fn package_kind_sets_workbook_content_type() { } assert_eq!(crate::XlsxKind::from_path("noext"), crate::XlsxKind::Workbook); } + +#[test] +fn doc_props_keep_boundary_whitespace() { + let mut wb = Workbook::new(); + wb.props = DocProps { + title: " Title ".into(), + subject: "\n".into(), + author: "\tMe\t".into(), + company: " Co ".into(), + keywords: " a, b ".into(), + description: "\n d\n".into(), + }; + let (back, _) = read_xlsx(&write_xlsx(&wb).unwrap()).unwrap(); + assert_eq!(back.props, wb.props); +}