From ada2188786fd646443c4fb3326e68e52ce84c90d Mon Sep 17 00:00:00 2001 From: RRFZ <247457381+Plastic-time@users.noreply.github.com> Date: Sun, 15 Nov 2026 11:17:46 -0500 Subject: [PATCH] Preserve XML quoted-attribute and line-ending regression tests Imported from storytold/craft-anything #1738 and #1726 at 8f3b7751, adapted only to shared parse_xml entry point. --- crates/plist/tests/plist_line_endings.rs | 17 ++++++++++++++ crates/plist/tests/plist_quoted_attributes.rs | 22 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 crates/plist/tests/plist_line_endings.rs create mode 100644 crates/plist/tests/plist_quoted_attributes.rs diff --git a/crates/plist/tests/plist_line_endings.rs b/crates/plist/tests/plist_line_endings.rs new file mode 100644 index 000000000..3f8f82b50 --- /dev/null +++ b/crates/plist/tests/plist_line_endings.rs @@ -0,0 +1,17 @@ +use craft_plist::{self as plist, Value}; + +/// Literal line endings normalize before entities, including keys and CDATA. +#[test] +fn xml_line_endings_follow_xml_rules() { + let xml = "a\rba\r\nb\rc\nd e"; + for encoding in 0..3 { + let bytes = match encoding { + 1 => [vec![0xff, 0xfe], xml.encode_utf16().flat_map(u16::to_le_bytes).collect()].concat(), + 2 => [vec![0xfe, 0xff], xml.encode_utf16().flat_map(u16::to_be_bytes).collect()].concat(), + _ => xml.as_bytes().to_vec(), + }; + let value = plist::parse_xml(&bytes).unwrap(); + assert_eq!(value.get("a\nb").and_then(Value::as_str), Some("a\nb\nc\nd\ref\ng")); + } + assert!(plist::parse_xml(b"a\r\nb").is_err()); +} diff --git a/crates/plist/tests/plist_quoted_attributes.rs b/crates/plist/tests/plist_quoted_attributes.rs new file mode 100644 index 000000000..54cd042ef --- /dev/null +++ b/crates/plist/tests/plist_quoted_attributes.rs @@ -0,0 +1,22 @@ +use craft_plist::{self as plist, Value}; + +/// Quoted delimiters belong to attributes, including on empty elements. +#[test] +fn quoted_tag_delimiters_preserve_values() { + for quote in ['\'', '"'] { + let xml = format!( + "b{quote}>界{quote}>key/{quote}>valueempty/{quote}/>" + ); + let value = plist::parse_xml(xml.as_bytes()).unwrap(); + assert_eq!(value.get("key").and_then(Value::as_str), Some("value")); + assert_eq!(value.get("empty").and_then(Value::as_str), Some("")); + } +} + +/// A quote that never closes must not turn later markup into a value. +#[test] +fn unterminated_attribute_quotes_are_rejected() { + for xml in ["value", "