mirror of
https://github.com/storytold/gridcraft.git
synced 2026-10-24 10:46:50 -06:00
fix(xlsx): keep leading and trailing whitespace in document properties on reopen (#554)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user