Author: tilman
Date: Wed Dec 17 12:29:50 2025
New Revision: 1930666

Log:
PDFBOX-6125: array types are not simple; add another test

Modified:
   
pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
   
pdfbox/branches/2.0/xmpbox/src/test/java/org/apache/xmpbox/xml/DomXmpParserTest.java

Modified: 
pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
==============================================================================
--- 
pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
    Wed Dec 17 12:28:38 2025        (r1930665)
+++ 
pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
    Wed Dec 17 12:29:50 2025        (r1930666)
@@ -335,13 +335,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
                 {
@@ -1134,13 +1134,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/2.0/xmpbox/src/test/java/org/apache/xmpbox/xml/DomXmpParserTest.java
==============================================================================
--- 
pdfbox/branches/2.0/xmpbox/src/test/java/org/apache/xmpbox/xml/DomXmpParserTest.java
        Wed Dec 17 12:28:38 2025        (r1930665)
+++ 
pdfbox/branches/2.0/xmpbox/src/test/java/org/apache/xmpbox/xml/DomXmpParserTest.java
        Wed Dec 17 12:29:50 2025        (r1930666)
@@ -817,7 +817,7 @@ public class DomXmpParserTest
         }
         catch (XmpParsingException ex)
         {
-            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);
@@ -827,6 +827,46 @@ public class DomXmpParserTest
     }
 
     @Test
+    public void testBadAttr3() throws XmpParsingException, 
TransformerException, UnsupportedEncodingException
+    {
+        // 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'?>";
+        try
+        {
+            new DomXmpParser().parse(s.getBytes("utf-8"));
+            fail("XmpParsingException expected");
+        }
+        catch (XmpParsingException ex)
+        {
+            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("utf-8"));
+        XmpSerializer serializer = new XmpSerializer();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        // make sure that nothing is lost in serialization
+        serializer.serialize(xmp2, baos, true);
+        try
+        {
+            new DomXmpParser().parse(baos.toByteArray());
+            fail("XmpParsingException expected");
+        }
+        catch (XmpParsingException ex)
+        {
+            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
     public void testBadSchema() throws XmpParsingException, 
UnsupportedEncodingException
     {
         // from file 130841.pdf

Reply via email to