From 19072e763772c65450a0dc3423dbe8791c98b565 Mon Sep 17 00:00:00 2001 From: Ricardo Benitez Date: Fri, 31 Oct 2025 22:36:12 +0100 Subject: [PATCH 1/4] fix: correctly handle empty elements There is a bug in which when we encounter empty elements, the parsing tree is shifted and the children are asigned to parent elements. One really easy fix is to handle that empty element. Signed-off-by: Ricardo Benitez --- src/reader.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/reader.rs b/src/reader.rs index e16055d..e148465 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -1109,6 +1109,7 @@ where } } Event::Comment(_) => {} + Event::Empty(_) => {} // Need o handle empty element to properly parse the tree _ => break, } } @@ -1772,6 +1773,44 @@ mod tests { ); } + #[test] + fn test_parse_placemark_children_with_empty_field() { + let kml_str = r#" + + Test Placemark + + CustomValue + + CustomValue2 + + + "#; + let f: Kml = kml_str.parse().unwrap(); + assert_eq!( + f, + Kml::Placemark(Placemark { + name: Some("Test Placemark".to_string()), + children: vec![Element { + name: "ExtendedData".to_string(), + children: vec![ + Element { + name: "CustomField".to_string(), + content: Some("CustomValue".to_string()), + ..Default::default() + }, + Element { + name: "AnotherCustomField".to_string(), + content: Some("CustomValue2".to_string()), + ..Default::default() + } + ], + ..Default::default() + }], + ..Default::default() + }) + ); + } + #[test] fn test_parse_doc_with_sibling_folders() { let kml_str = r#" From 29a852a278b64df7b1ce1f1a37c627e20b899c55 Mon Sep 17 00:00:00 2001 From: Ricardo Benitez Date: Sun, 2 Nov 2025 20:13:21 +0100 Subject: [PATCH 2/4] fix: fix cargo clippy error Signed-off-by: Ricardo Benitez --- src/types/vec2.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/types/vec2.rs b/src/types/vec2.rs index dd9e41f..e110e06 100644 --- a/src/types/vec2.rs +++ b/src/types/vec2.rs @@ -23,17 +23,14 @@ impl Default for Vec2 { } #[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Default)] pub enum Units { + #[default] Fraction, Pixels, InsetPixels, } -impl Default for Units { - fn default() -> Self { - Self::Fraction - } -} impl FromStr for Units { type Err = Error; From 41a910b81ac49b844bd949e06da1de729b4905b2 Mon Sep 17 00:00:00 2001 From: Ricardo Benitez Date: Fri, 7 Nov 2025 10:55:42 +0000 Subject: [PATCH 3/4] style: update style of vec2 Signed-off-by: Ricardo Benitez --- src/types/vec2.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/types/vec2.rs b/src/types/vec2.rs index e110e06..a81012c 100644 --- a/src/types/vec2.rs +++ b/src/types/vec2.rs @@ -22,8 +22,7 @@ impl Default for Vec2 { } } -#[derive(Clone, Debug, PartialEq, Eq)] -#[derive(Default)] +#[derive(Clone, Debug, PartialEq, Eq, Default)] pub enum Units { #[default] Fraction, @@ -31,7 +30,6 @@ pub enum Units { InsetPixels, } - impl FromStr for Units { type Err = Error; From 16f0a272a48caa088796258daa07f047175b5bba Mon Sep 17 00:00:00 2001 From: Ricardo Benitez Date: Sat, 22 Nov 2025 13:56:02 +0100 Subject: [PATCH 4/4] refactor: join empty statements Signed-off-by: Ricardo Benitez --- src/reader.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/reader.rs b/src/reader.rs index e148465..d545ff3 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -1108,8 +1108,7 @@ where break; } } - Event::Comment(_) => {} - Event::Empty(_) => {} // Need o handle empty element to properly parse the tree + Event::Comment(_) | Event::Empty(_) => {} _ => break, } }