From ff2d72a7acf6b86517f010b87ab7847fe97a9df5 Mon Sep 17 00:00:00 2001 From: Thomas Krause Date: Thu, 15 Aug 2024 15:44:40 +0200 Subject: [PATCH] Do not create metadata labels with empty name in XLSX importer --- src/exporter/saltxml/corpus_structure.rs | 2 +- src/exporter/saltxml/document.rs | 2 +- src/importer/xlsx.rs | 20 +++++++++++--------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/exporter/saltxml/corpus_structure.rs b/src/exporter/saltxml/corpus_structure.rs index 61c9fd0d..5651b560 100644 --- a/src/exporter/saltxml/corpus_structure.rs +++ b/src/exporter/saltxml/corpus_structure.rs @@ -56,7 +56,7 @@ impl SaltCorpusStructureMapper { project_elem.write_inner_content::<_, Error>(|writer| { writer .create_element("sCorpusGraphs") - .write_inner_content::<_, Error>(|mut writer| { + .write_inner_content::<_, Error>(|writer| { writer .create_element("labels") .with_attribute(("xsi:type", "saltCore:SFeature")) diff --git a/src/exporter/saltxml/document.rs b/src/exporter/saltxml/document.rs index 91cbb531..2d871f67 100644 --- a/src/exporter/saltxml/document.rs +++ b/src/exporter/saltxml/document.rs @@ -77,7 +77,7 @@ impl SaltDocumentGraphMapper { .get_value_for_item(&document_node_id, &NODE_NAME_KEY)? .context("Missing node name for document graph")?; let salt_id = format!("T::salt:/{node_name}"); - graph_tag.write_inner_content::<_, Error>(|mut writer| { + graph_tag.write_inner_content::<_, Error>(|writer| { writer .create_element("labels") .with_attribute(("xsi:type", "saltCore:SElementId")) diff --git a/src/importer/xlsx.rs b/src/importer/xlsx.rs index 6b6d2414..85630996 100644 --- a/src/importer/xlsx.rs +++ b/src/importer/xlsx.rs @@ -382,15 +382,17 @@ impl ImportSpreadsheet { if let Some(value_cell) = entry_map.get(&2) { let kv = key_cell.get_value(); let key = kv.trim(); - let (ns, name) = split_qname(key); - let vv = value_cell.get_value(); - let value = vv.trim(); - update.add_event(UpdateEvent::AddNodeLabel { - node_name: doc_path.to_string(), - anno_ns: ns.map_or("".to_string(), str::to_string), - anno_name: name.to_string(), - anno_value: value.to_string(), - })?; + if !key.is_empty() { + let (ns, name) = split_qname(key); + let vv = value_cell.get_value(); + let value = vv.trim(); + update.add_event(UpdateEvent::AddNodeLabel { + node_name: doc_path.to_string(), + anno_ns: ns.map_or("".to_string(), str::to_string), + anno_name: name.to_string(), + anno_value: value.to_string(), + })?; + } } } }