Author: tilman
Date: Fri Nov 28 13:38:06 2025
New Revision: 1930056
Log:
PDFBOX-6106: catch incorrect type when in strict mode
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
Fri Nov 28 13:37:04 2025 (r1930055)
+++
pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
Fri Nov 28 13:38:06 2025 (r1930056)
@@ -270,13 +270,21 @@ public class DomXmpParser
ComplexPropertyContainer container = schema.getContainer();
PropertyType type = checkPropertyDefinition(xmp,
new QName(attr.getNamespaceURI(), attr.getLocalName()));
-
- //Default to text if no type is found
- if( type == null)
+
+ // PDFBOX-2318, PDFBOX-6106: Default to text if no type is found
+ if (type == null)
{
- type = TypeMapping.createPropertyType(Types.Text,
Cardinality.Simple);
+ if (strictParsing)
+ {
+ throw new XmpParsingException(ErrorType.InvalidType, "No
type defined for {" + attr.getNamespaceURI() + "}"
+ + attr.getLocalName());
+ }
+ else
+ {
+ type = TypeMapping.createPropertyType(Types.Text,
Cardinality.Simple);
+ }
}
-
+
try
{
AbstractSimpleProperty sp =
tm.instanciateSimpleProperty(namespace, schema.getPrefix(),
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
Fri Nov 28 13:37:04 2025 (r1930055)
+++
pdfbox/branches/2.0/xmpbox/src/test/java/org/apache/xmpbox/xml/DomXmpParserTest.java
Fri Nov 28 13:38:06 2025 (r1930056)
@@ -26,6 +26,7 @@ import java.io.UnsupportedEncodingExcept
import org.apache.xmpbox.XMPMetadata;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
import org.junit.Test;
/**
@@ -69,4 +70,42 @@ public class DomXmpParserTest
assertEquals("B", xmp.getPDFIdentificationSchema().getConformance());
assertEquals((Integer) 3, xmp.getPDFIdentificationSchema().getPart());
}
+
+ /**
+ * PDFBOX-6106: Check that "pdf:CreationDate='2004-01-30T17:21:50Z'" is
detected as incorrect.
+ * (Only Keywords, PDFVersion, and Producer are allowed in strict mode)
+ *
+ * @throws XmpParsingException
+ */
+ @Test
+ public void testPDFBox6106() throws XmpParsingException,
UnsupportedEncodingException
+ {
+ // from file 001358.pdf
+ String s = "<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'
bytes='647'?>\n" +
+ "<rdf:RDF
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'\n" +
+ " xmlns:iX='http://ns.adobe.com/iX/1.0/'>\n" +
+ " <rdf:Description about=''\n" +
+ "
xmlns='http://ns.adobe.com/pdf/1.3/'\n" +
+ "
xmlns:pdf='http://ns.adobe.com/pdf/1.3/'\n" +
+ "
pdf:CreationDate='2004-01-30T17:21:50Z'\n" +
+ " pdf:ModDate='2004-01-30T17:21:50Z'\n" +
+ " pdf:Producer='Acrobat Distiller 5.0.5
(Windows)'/>\n" +
+ " <rdf:Description about=''\n" +
+ "
xmlns='http://ns.adobe.com/xap/1.0/'\n" +
+ "
xmlns:xap='http://ns.adobe.com/xap/1.0/'\n" +
+ "
xap:CreateDate='2004-01-30T17:21:50Z'\n" +
+ "
xap:ModifyDate='2004-01-30T17:21:50Z'\n" +
+ "
xap:MetadataDate='2004-01-30T17:21:50Z'/>\n" +
+ "</rdf:RDF><?xpacket end='r'?>";
+ DomXmpParser xmpParser = new DomXmpParser();
+ try
+ {
+ xmpParser.parse(s.getBytes("utf-8"));
+ fail("XmpParsingException expected");
+ }
+ catch (XmpParsingException ex)
+ {
+ assertEquals("No type defined for
{http://ns.adobe.com/pdf/1.3/}CreationDate", ex.getMessage());
+ }
+ }
}