Skip to content

Commit 82423fa

Browse files
committed
PDFBOX-6125: array types are not simple; add another test
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1930667 13f79535-47bb-0310-9956-ffa450edef68
1 parent cd6389b commit 82423fa

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,13 @@ private void parseDescriptionRootAttr(XMPMetadata xmp, Element description, Attr
336336
type = TypeMapping.createPropertyType(Types.Text, Cardinality.Simple);
337337
}
338338
}
339-
else if (!type.type().isSimple())
339+
else if (!type.type().isSimple() || type.card().isArray())
340340
{
341341
if (strictParsing)
342342
{
343343
throw new XmpParsingException(ErrorType.InvalidType, "The type '" +
344344
type.type().name() + "' in '" + attr.getPrefix() + ":" + attr.getLocalName() + "=" + attr.getValue()
345-
+ "' is a structured type, but attributes are simple types");
345+
+ "' is a structured or array type, but attributes are simple types");
346346
}
347347
else
348348
{
@@ -1129,13 +1129,13 @@ else if (XmpConstants.DEFAULT_RDF_PREFIX.equals(attr.getPrefix()))
11291129
type = TypeMapping.createPropertyType(Types.Text, Cardinality.Simple);
11301130
}
11311131
}
1132-
else if (!type.type().isSimple())
1132+
else if (!type.type().isSimple() || type.card().isArray())
11331133
{
11341134
if (strictParsing)
11351135
{
11361136
throw new XmpParsingException(ErrorType.InvalidType, "The type '" +
11371137
type.type().name() + "' in '" + attr.getPrefix() + ":" + attr.getLocalName() + "=" + attr.getValue()
1138-
+ "' is a structured type, but attributes are simple types");
1138+
+ "' is a structured or array type, but attributes are simple types");
11391139
}
11401140
else
11411141
{

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,14 +781,43 @@ void testBadAttr2() throws XmpParsingException
781781
XmpParsingException ex = assertThrows(
782782
XmpParsingException.class,
783783
() -> xmpParser1.parse(s.getBytes(StandardCharsets.UTF_8)));
784-
assertEquals("The type 'Flash' in 'exif:Flash=1' is a structured type, but attributes are simple types", ex.getMessage());
784+
assertEquals("The type 'Flash' in 'exif:Flash=1' is a structured or array type, but attributes are simple types", ex.getMessage());
785785
final DomXmpParser xmpParser2 = new DomXmpParser();
786786
xmpParser2.setStrictParsing(false);
787787
XMPMetadata xmp = xmpParser2.parse(s.getBytes(StandardCharsets.UTF_8));
788788
ExifSchema exifSchema = (ExifSchema) xmp.getSchema(ExifSchema.class);
789789
assertEquals("[Flash=TextType:1]", exifSchema.getProperty(ExifSchema.FLASH).toString());
790790
}
791791

792+
@Test
793+
void testBadAttr3() throws XmpParsingException, TransformerException
794+
{
795+
// test text in attribute which should have been an array property
796+
String s = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
797+
"<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d' bytes='1064'?><rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n" +
798+
" <rdf:Description xmlns=\"http://purl.org/dc/elements/1.1/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" about=\"\" dc:creator=\"Creator\" />\n" +
799+
"</rdf:RDF><?xpacket end='r'?>";
800+
final DomXmpParser xmpParser1 = new DomXmpParser();
801+
XmpParsingException ex = assertThrows(XmpParsingException.class,
802+
() -> xmpParser1.parse(s.getBytes(StandardCharsets.UTF_8)));
803+
assertEquals("The type 'Text' in 'dc:creator=Creator' is a structured or array type, but attributes are simple types", ex.getMessage());
804+
DomXmpParser xmpParser2 = new DomXmpParser();
805+
xmpParser2.setStrictParsing(false);
806+
XMPMetadata xmp2 = xmpParser2.parse(s.getBytes(StandardCharsets.UTF_8));
807+
XmpSerializer serializer = new XmpSerializer();
808+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
809+
// make sure that nothing is lost in serialization
810+
serializer.serialize(xmp2, baos, true);
811+
final DomXmpParser xmpParser3 = new DomXmpParser();
812+
ex = assertThrows(XmpParsingException.class, () -> xmpParser3.parse(baos.toByteArray()));
813+
assertEquals("Invalid array definition, expecting Seq and found Text [prefix=dc; name=creator]", ex.getMessage());
814+
DomXmpParser xmpParser4 = new DomXmpParser();
815+
xmpParser4.setStrictParsing(false);
816+
XMPMetadata xmp4 = xmpParser4.parse(baos.toByteArray());
817+
DublinCoreSchema dublinCoreSchema = xmp4.getDublinCoreSchema();
818+
assertEquals("[creator=TextType:Creator]", dublinCoreSchema.getProperty(DublinCoreSchema.CREATOR).toString());
819+
}
820+
792821
@Test
793822
void testBadSchema() throws XmpParsingException
794823
{

0 commit comments

Comments
 (0)