Merge pull request #990 from MrDevKing/feature_pdfvalidator-error-parse-xmp-metadata
Fix empty ValidationResult when XMP metadata contains invalid XML characters (#989)
This commit is contained in:
@@ -150,7 +150,14 @@ public class PDFValidator extends Validator {
|
|||||||
|
|
||||||
final DocumentBuilder builder = factory.newDocumentBuilder();
|
final DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
final InputSource is = new InputSource(new StringReader(xmp));
|
final InputSource is = new InputSource(new StringReader(xmp));
|
||||||
|
try {
|
||||||
docXMP = builder.parse(is);
|
docXMP = builder.parse(is);
|
||||||
|
} catch (Exception e) {
|
||||||
|
context.addResultItem(
|
||||||
|
new ValidationResultItem(ESeverity.error, "XMP Metadata: Could not parse XMP metadata")
|
||||||
|
.setSection(10).setPart(EPart.pdf));
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
final XPathFactory xpathFactory = XPathFactory.newInstance();
|
final XPathFactory xpathFactory = XPathFactory.newInstance();
|
||||||
|
|
||||||
|
|||||||
@@ -169,6 +169,16 @@ public class PDFValidatorTest extends ResourceCase {
|
|||||||
|
|
||||||
assertEquals(false, actual.contains("<error"));// issue 18: "ConformanceLevel not found" should not be
|
assertEquals(false, actual.contains("<error"));// issue 18: "ConformanceLevel not found" should not be
|
||||||
// reported since it's actually there
|
// reported since it's actually there
|
||||||
|
|
||||||
|
contents = getResourceAsByteArray("invalidXMP-ParseError.pdf");
|
||||||
|
|
||||||
|
pv.setFilenameAndContents("invalidXMP-ParseError.pdf", contents);
|
||||||
|
vc.clear();
|
||||||
|
pv.validate();
|
||||||
|
actual = pv.getXMLResult();
|
||||||
|
|
||||||
|
assertEquals(true, actual
|
||||||
|
.contains("<error type=\"10\">XMP Metadata: Could not parse XMP metadata</error>"));
|
||||||
} catch (final IrrecoverableValidationError e) {
|
} catch (final IrrecoverableValidationError e) {
|
||||||
// ignore, will be in XML output anyway
|
// ignore, will be in XML output anyway
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
validator/src/test/resources/invalidXMP-ParseError.pdf
Normal file
BIN
validator/src/test/resources/invalidXMP-ParseError.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user