Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/utils/xml_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ pub fn start_element_to_string(e: &BytesStart, flags: &Flags) -> String {
complete_tag.push_str(&local_name_to_string(e.name().as_ref()));

for attr in get_attributes(e) {
if !flags.lossless && matches!(attr.0.as_str(), "nextvalue" | "UUID" | "index") {
if !flags.lossless
&& matches!(
attr.0.as_str(),
"nextvalue" | "UUID" | "index" | "Collapsed"
)
{
continue;
}
complete_tag.push(' ');
Expand Down Expand Up @@ -413,6 +418,16 @@ pub fn extract_values_from_xml_paths(
#[cfg(test)]
mod tests {
use super::*;
use crate::config::{Flags, OutputTree};
use quick_xml::events::BytesStart;

fn make_flags(lossless: bool) -> Flags {
Flags {
lossless,
parse_all_lines: false,
output_tree: OutputTree::Db,
}
}

#[test]
fn test_escape_xml_entities() {
Expand All @@ -421,4 +436,26 @@ mod tests {
"This & that "test" <tag>"
);
}

#[test]
fn test_collapsed_attribute_stripped_in_lossy_mode() {
let xml = b"Step enable=\"True\" id=\"68\" name=\"If\" Collapsed=\"False\"";
let e = BytesStart::from_content(std::str::from_utf8(xml).unwrap(), 4);
let result = start_element_to_string(&e, &make_flags(false));
assert!(
!result.contains("Collapsed"),
"Collapsed attribute should be stripped in lossy mode, got: {result}"
);
}

#[test]
fn test_collapsed_attribute_preserved_in_lossless_mode() {
let xml = b"Step enable=\"True\" id=\"68\" name=\"If\" Collapsed=\"False\"";
let e = BytesStart::from_content(std::str::from_utf8(xml).unwrap(), 4);
let result = start_element_to_string(&e, &make_flags(true));
assert!(
result.contains("Collapsed=\"False\""),
"Collapsed attribute should be preserved in lossless mode, got: {result}"
);
}
}
Loading