mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 10:51:11 +01:00
Scripts: text beside an XMP array keeps the property as written
A property holding text next to its rdf:Bag, rdf:Seq or rdf:Alt was read as an array of simple items, and serialize() dropped the text. Such a property is now kept as the XML it was written in. Test: text_beside_an_array_is_kept in crates/js/src/xmp_tests.rs.
This commit is contained in:
1 parent
b8bf41b7a9
commit
84acd52710
2 files changed
+13
-1
No files matched your search
@@ -526,7 +526,7 @@ fn read_property(p: &El, scope: &mut Scope, registry: &mut Registry) -> Result<P
|
||||
&& text_of(p).trim().is_empty()
|
||||
{
|
||||
Value::Simple { text: (*v).to_string(), uri: true }
|
||||
} else if let (Some(array), true) = (array_of(&children, scope), own.is_empty()) {
|
||||
} else if let (Some(array), true) = (array_of(&children, scope), own.is_empty() && text_of(p).trim().is_empty()) {
|
||||
array
|
||||
} else {
|
||||
// A written packet puts a property 3 elements deep (`x:xmpmeta`, `rdf:RDF`,
|
||||
|
||||
@@ -368,6 +368,18 @@ fn namespaces_inside_kept_values_are_registered() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Text beside an array's container keeps the property as it was written.
|
||||
#[test]
|
||||
fn text_beside_an_array_is_kept() {
|
||||
let packet = "<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'><rdf:Description xmlns:a='http://a/'>\
|
||||
<a:p>before<rdf:Bag><rdf:li>x</rdf:li></rdf:Bag>after</a:p></rdf:Description></rdf:RDF>";
|
||||
let mut registry = Registry::default();
|
||||
let meta = xmp::parse(packet, &mut registry).unwrap();
|
||||
let out = xmp::serialize(&meta, ®istry, false).unwrap();
|
||||
assert!(out.contains("before") && out.contains("after"), "{out}");
|
||||
assert_eq!(xmp::parse(&out, &mut registry), Ok(meta));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn array_forms_follow_their_options() {
|
||||
assert_eq!(Form::from_options(0x200), Form::Bag);
|
||||
|
||||
Reference in new issue
Block a user