fix(xlsx): keep leading and trailing whitespace in document properties on reopen (#554)

This commit is contained in:
MarekSpodBiedry
2026-10-12 08:28:50 +02:00
parent 3926d21aa9
commit ea6bb98fc7
2 changed files with 17 additions and 2 deletions
+2 -2
View File
@@ -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
+15
View File
@@ -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);
}