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.
This commit is contained in:
RRFZ
2026-11-15 11:17:46 -05:00
committed by Dylan M. Taylor
parent 4c4ad5d20f
commit ada2188786
2 changed files with 39 additions and 0 deletions
+17
View File
@@ -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 = "<plist><dict><key>a\rb</key><string>a\r\nb\rc\nd&#13;e<![CDATA[f\r\ng]]></string></dict></plist>";
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"<plist><string>a\r\nb</dict></plist>").is_err());
}
@@ -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!(
"<plist note={quote}a>b{quote}><dict><key note={quote}/>界{quote}>key</key><string note={quote}>/{quote}>value</string><key>empty</key><string note={quote}>/{quote}/></dict></plist>"
);
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 ["<plist><string note=\"oops>value</string></plist>", "<plist><string note='oops>value</string></plist>"] {
assert!(plist::parse_xml(xml.as_bytes()).is_err(), "{xml}");
}
}