Skip to content

Commit

Permalink
Fix proposal for parse_xml in case of unique child: (#849)
Browse files Browse the repository at this point in the history
* Fix proposal for parse_xml in case of unique child:
- Modify single node map insert behaviour -> process_node instead of recurse
- Add tests for unique child situation

* apply fix to latest main

---------

Co-authored-by: Pavlos Rontidis <[email protected]>
  • Loading branch information
ScriptToddler and pront authored Sep 13, 2024
1 parent 8c428dd commit 3ca9f6c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/849.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The `parse_xml` function now doesn't add an unnecessary `text` key when processing single nodes.
2 changes: 1 addition & 1 deletion src/parsing/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fn process_node(node: Node, config: &ParseXmlConfig) -> Value {

map.insert(
node.tag_name().name().to_string().into(),
Value::Object(recurse(node)),
process_node(node, config),
);

Value::Object(map)
Expand Down
12 changes: 12 additions & 0 deletions src/stdlib/parse_xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,18 @@ mod tests {
)),
tdef: type_def(),
}

if_no_sibling {
args: func_args![ value: "<root><a>test</a></root>"],
want: Ok(value!({ "root": { "a": "test" } })),
tdef: type_def(),
}

if_no_sibling2 {
args: func_args![ value: "<root><a><a1>test</a1></a><b>test2</b></root>"],
want: Ok(value!({ "root": { "a": { "a1": "test" }, "b" : "test2" } })),
tdef: type_def(),
}
];

#[test]
Expand Down

0 comments on commit 3ca9f6c

Please sign in to comment.