Author: tilman
Date: Wed Dec 17 12:30:00 2025
New Revision: 1930668
Log:
PDFBOX-6125: array types are not simple; add another test
Modified:
pdfbox/branches/3.0/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
pdfbox/branches/3.0/xmpbox/src/test/java/org/apache/xmpbox/xml/DomXmpParserTest.java
Modified:
pdfbox/branches/3.0/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
==============================================================================
---
pdfbox/branches/3.0/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
Wed Dec 17 12:29:55 2025 (r1930667)
+++
pdfbox/branches/3.0/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
Wed Dec 17 12:30:00 2025 (r1930668)
@@ -336,13 +336,13 @@ public class DomXmpParser
type = TypeMapping.createPropertyType(Types.Text,
Cardinality.Simple);
}
}
- else if (!type.type().isSimple())
+ else if (!type.type().isSimple() || type.card().isArray())
{
if (strictParsing)
{
throw new XmpParsingException(ErrorType.InvalidType, "The
type '" +
type.type().name() + "' in '" + attr.getPrefix() +
":" + attr.getLocalName() + "=" + attr.getValue()
- + "' is a structured type, but attributes are
simple types");
+ + "' is a structured or array type, but attributes
are simple types");
}
else
{
@@ -1129,13 +1129,13 @@ public class DomXmpParser
type = TypeMapping.createPropertyType(Types.Text,
Cardinality.Simple);
}
}
- else if (!type.type().isSimple())
+ else if (!type.type().isSimple() || type.card().isArray())
{
if (strictParsing)
{
throw new
XmpParsingException(ErrorType.InvalidType, "The type '" +
type.type().name() + "' in '" +
attr.getPrefix() + ":" + attr.getLocalName() + "=" + attr.getValue()
- + "' is a structured type, but attributes
are simple types");
+ + "' is a structured or array type, but
attributes are simple types");
}
else
{
Modified:
pdfbox/branches/3.0/xmpbox/src/test/java/org/apache/xmpbox/xml/DomXmpParserTest.java
==============================================================================
---
pdfbox/branches/3.0/xmpbox/src/test/java/org/apache/xmpbox/xml/DomXmpParserTest.java
Wed Dec 17 12:29:55 2025 (r1930667)
+++
pdfbox/branches/3.0/xmpbox/src/test/java/org/apache/xmpbox/xml/DomXmpParserTest.java
Wed Dec 17 12:30:00 2025 (r1930668)
@@ -783,7 +783,7 @@ class DomXmpParserTest
XmpParsingException ex = assertThrows(
XmpParsingException.class,
() -> xmpParser1.parse(s.getBytes(StandardCharsets.UTF_8)));
- assertEquals("The type 'Flash' in 'exif:Flash=1' is a structured type,
but attributes are simple types", ex.getMessage());
+ assertEquals("The type 'Flash' in 'exif:Flash=1' is a structured or
array type, but attributes are simple types", ex.getMessage());
final DomXmpParser xmpParser2 = new DomXmpParser();
xmpParser2.setStrictParsing(false);
XMPMetadata xmp = xmpParser2.parse(s.getBytes(StandardCharsets.UTF_8));
@@ -792,6 +792,35 @@ class DomXmpParserTest
}
@Test
+ void testBadAttr3() throws XmpParsingException, TransformerException
+ {
+ // test text in attribute which should have been an array property
+ String s = "<?xml version=\"1.0\" encoding=\"UTF-8\"
standalone=\"no\"?>\n" +
+"<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d' bytes='1064'?><rdf:RDF
xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n" +
+" <rdf:Description xmlns=\"http://purl.org/dc/elements/1.1/\"
xmlns:dc=\"http://purl.org/dc/elements/1.1/\" about=\"\" dc:creator=\"Creator\"
/>\n" +
+"</rdf:RDF><?xpacket end='r'?>";
+ final DomXmpParser xmpParser1 = new DomXmpParser();
+ XmpParsingException ex = assertThrows(XmpParsingException.class,
+ () -> xmpParser1.parse(s.getBytes(StandardCharsets.UTF_8)));
+ assertEquals("The type 'Text' in 'dc:creator=Creator' is a structured
or array type, but attributes are simple types", ex.getMessage());
+ DomXmpParser xmpParser2 = new DomXmpParser();
+ xmpParser2.setStrictParsing(false);
+ XMPMetadata xmp2 =
xmpParser2.parse(s.getBytes(StandardCharsets.UTF_8));
+ XmpSerializer serializer = new XmpSerializer();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ // make sure that nothing is lost in serialization
+ serializer.serialize(xmp2, baos, true);
+ final DomXmpParser xmpParser3 = new DomXmpParser();
+ ex = assertThrows(XmpParsingException.class, () ->
xmpParser3.parse(baos.toByteArray()));
+ assertEquals("Invalid array definition, expecting Seq and found Text
[prefix=dc; name=creator]", ex.getMessage());
+ DomXmpParser xmpParser4 = new DomXmpParser();
+ xmpParser4.setStrictParsing(false);
+ XMPMetadata xmp4 = xmpParser4.parse(baos.toByteArray());
+ DublinCoreSchema dublinCoreSchema = xmp4.getDublinCoreSchema();
+ assertEquals("[creator=TextType:Creator]",
dublinCoreSchema.getProperty(DublinCoreSchema.CREATOR).toString());
+ }
+
+ @Test
void testBadSchema() throws XmpParsingException
{
// from file 130841.pdf