Skip to content

Commit 6b00f96

Browse files
committed
PDFBOX-5660: expand test coverage, correct exception message
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1930628 13f79535-47bb-0310-9956-ffa450edef68
1 parent 1039740 commit 6b00f96

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ private void parseSchemaExtensions(final XMPMetadata xmp, final Element descript
225225
if (!tm.isDefinedSchema(schemaExtension.getNamespaceURI()))
226226
{
227227
throw new XmpParsingException(ErrorType.NoSchema,
228-
"This namespace is not a schema or a structured type : " + namespace);
228+
"This namespace is not from a schema: " + namespace);
229229
}
230230
PropertyType type = checkPropertyDefinition(xmp, DomHelper.getQName(schemaExtension));
231231
final XMPSchema schema = tm.getSchemaFactory(namespace).createXMPSchema(xmp, schemaExtension.getPrefix());
@@ -366,7 +366,7 @@ private void parseChildrenAsProperties(XMPMetadata xmp, List<Element> properties
366366
if (!tm.isDefinedSchema(namespace))
367367
{
368368
throw new XmpParsingException(ErrorType.NoSchema,
369-
"This namespace is not a schema or a structured type : " + namespace);
369+
"This namespace is not from a schema: " + namespace);
370370
}
371371
if (isSchemaExtensionProperty(property))
372372
{

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,4 +761,31 @@ void testBadAttr2() throws XmpParsingException
761761
ExifSchema exifSchema = (ExifSchema) xmp.getSchema(ExifSchema.class);
762762
assertEquals("[Flash=TextType:1]", exifSchema.getProperty(ExifSchema.FLASH).toString());
763763
}
764+
765+
@Test
766+
void testBadSchema() throws XmpParsingException
767+
{
768+
// from file 130841.pdf
769+
// structured type used like a schema
770+
String s = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
771+
"<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?><?adobe-xap-filters esc=\"CRLF\"?>\n" +
772+
"<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"\n" +
773+
" x:xmptk=\"XMP toolkit\">\n" +
774+
" <rdf:RDF xmlns:iX=\"http://ns.adobe.com/iX/1.0/\"\n" +
775+
" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n" +
776+
" <rdf:Description xmlns:stJob=\"http://ns.adobe.com/xap/1.0/sType/Job#\"\n" +
777+
" rdf:about=\"uuid\"\n" +
778+
" stJob:id=\"jobid\"\n" +
779+
" stJob:name=\"some name\">\n" +
780+
" <stJob:URL>https://pdfbox.apache.org</stJob:URL>\n" +
781+
" </rdf:Description>\n" +
782+
" </rdf:RDF>\n" +
783+
"</x:xmpmeta><?xpacket end='w'?>";
784+
785+
final DomXmpParser xmpParser1 = new DomXmpParser();
786+
XmpParsingException ex = assertThrows(
787+
XmpParsingException.class,
788+
() -> xmpParser1.parse(s.getBytes(StandardCharsets.UTF_8)));
789+
assertEquals("This namespace is not from a schema: http://ns.adobe.com/xap/1.0/sType/Job#", ex.getMessage());
790+
}
764791
}

0 commit comments

Comments
 (0)