Skip to content

Commit a1d2f7f

Browse files
committed
PDFBOX-6135: fallback to text for undefined property in lenient mode + test
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1930898 13f79535-47bb-0310-9956-ffa450edef68
1 parent ecc4e9a commit a1d2f7f

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -824,11 +824,15 @@ private AbstractStructuredType parseLiDescription(XMPMetadata xmp, QName parentQ
824824
PropertyType type = pm.getPropertyType(name);
825825
if (type == null)
826826
{
827-
// not defined
828-
throw new XmpParsingException(ErrorType.NoType, "Type '" + prefix + ":" + name + "' not defined in "
829-
+ liDescriptionElementChild.getNamespaceURI());
827+
if (strictParsing)
828+
{
829+
throw new XmpParsingException(ErrorType.NoType, "Type '" + prefix + ":" + name + "' not defined in "
830+
+ liDescriptionElementChild.getNamespaceURI());
831+
}
832+
// PDFBOX-6135: Default to text if no type is found
833+
type = TypeMapping.createPropertyType(Types.Text, Cardinality.Simple);
830834
}
831-
else if (type.card().isArray())
835+
if (type.card().isArray())
832836
{
833837
ArrayProperty array = tm.createArrayProperty(namespace, prefix, name, type.card());
834838
ast.getContainer().addProperty(array);

xmpbox/src/test/java/org/apache/xmpbox/xml/DomXmpParserTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,37 @@ void testBadProp() throws XmpParsingException, TransformerException
10721072
assertEquals("Cover", dublinCoreSchema3.getCoverage());
10731073
}
10741074

1075+
@Test
1076+
void testBadProp2() throws XmpParsingException
1077+
{
1078+
// PDFBOX-6135: from file 000316.pdf, stRef:documentName isn't defined
1079+
String s =
1080+
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
1081+
"<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?><x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"3.1-701\">\n" +
1082+
" <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n" +
1083+
" <rdf:Description xmlns:stRef=\"http://ns.adobe.com/xap/1.0/sType/ResourceRef#\" xmlns:xapMM=\"http://ns.adobe.com/xap/1.0/mm/\" rdf:about=\"\">\n" +
1084+
" <xapMM:DocumentID>uuid:CE03288B61A6DB11A55CA11F14F48514</xapMM:DocumentID>\n" +
1085+
" <xapMM:InstanceID>uuid:474647e9-680a-47dc-83d5-ba3f3a7e2a67</xapMM:InstanceID>\n" +
1086+
" <xapMM:DerivedFrom rdf:parseType=\"Resource\">\n" +
1087+
" <stRef:documentName>uuid:8705447f-b80d-4cc8-82f7-0ec27187edfe</stRef:documentName>\n" +
1088+
" <stRef:documentID>uuid:b2f88223-2723-430d-b93c-3503ccb0e34b</stRef:documentID>\n" +
1089+
" </xapMM:DerivedFrom>\n" +
1090+
" </rdf:Description>\n" +
1091+
" </rdf:RDF>\n" +
1092+
"</x:xmpmeta><?xpacket end=\"w\"?>";
1093+
final DomXmpParser xmpParser1 = new DomXmpParser();
1094+
XmpParsingException ex = assertThrows(XmpParsingException.class,
1095+
() -> xmpParser1.parse(s.getBytes(StandardCharsets.UTF_8)));
1096+
assertEquals("Type 'stRef:documentName' not defined in http://ns.adobe.com/xap/1.0/sType/ResourceRef#", ex.getMessage());
1097+
final DomXmpParser xmpParser2 = new DomXmpParser();
1098+
xmpParser2.setStrictParsing(false);
1099+
XMPMetadata xmp2 = xmpParser2.parse(s.getBytes(StandardCharsets.UTF_8));
1100+
XMPMediaManagementSchema xmpMediaManagementSchema = xmp2.getXMPMediaManagementSchema();
1101+
ResourceRefType derived = xmpMediaManagementSchema.getDerivedFromProperty();
1102+
assertEquals("uuid:b2f88223-2723-430d-b93c-3503ccb0e34b", derived.getDocumentID());
1103+
assertEquals("[documentName=TextType:uuid:8705447f-b80d-4cc8-82f7-0ec27187edfe]", derived.getProperty("documentName").toString());
1104+
}
1105+
10751106
@Test
10761107
void testParseFailure() throws XmpParsingException
10771108
{

0 commit comments

Comments
 (0)