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); +}