From 62d67e71f4bbbb3f99ca97de2c73ef502ba203e8 Mon Sep 17 00:00:00 2001 From: Romain Deltour Date: Thu, 13 Oct 2022 15:57:24 +0200 Subject: [PATCH] fix: report fatal XML parsing errors only once as RSC-016 --- src/main/java/com/adobe/epubcheck/xml/XMLParser.java | 5 ++++- src/test/java/com/adobe/epubcheck/ocf/OPFPeekerTest.java | 6 ++++-- src/test/resources/epub3/03-resources/resources.feature | 2 -- .../06-content-document/content-document-xhtml.feature | 2 -- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/adobe/epubcheck/xml/XMLParser.java b/src/main/java/com/adobe/epubcheck/xml/XMLParser.java index 8e183ce7b..6fd924096 100755 --- a/src/main/java/com/adobe/epubcheck/xml/XMLParser.java +++ b/src/main/java/com/adobe/epubcheck/xml/XMLParser.java @@ -162,7 +162,10 @@ public void process() report.message(MessageId.PKG_008, EPUBLocation.of(context), context.path); } catch (SAXException e) { - report.message(MessageId.RSC_005, EPUBLocation.of(context), e.getMessage()); + // All errors should have already been reported by the error handler + if (report.getFatalErrorCount() == 0) { + report.message(MessageId.RSC_016, EPUBLocation.of(context), e.getMessage()); + } } } diff --git a/src/test/java/com/adobe/epubcheck/ocf/OPFPeekerTest.java b/src/test/java/com/adobe/epubcheck/ocf/OPFPeekerTest.java index d1098db89..51bf56780 100644 --- a/src/test/java/com/adobe/epubcheck/ocf/OPFPeekerTest.java +++ b/src/test/java/com/adobe/epubcheck/ocf/OPFPeekerTest.java @@ -151,14 +151,16 @@ public void testRetrieveVersionNoVersionAttribute() @Test public void testRetrieveVersionNoEqualSign() { - Collections.addAll(expectedErrors, MessageId.RSC_005, MessageId.RSC_005); + Collections.addAll(expectedErrors, MessageId.RSC_005); + Collections.addAll(expectedFatals, MessageId.RSC_016); retrieveData("noEqual.opf"); } @Test public void testRetrieveVersionValueWithoutQuotes() { - Collections.addAll(expectedErrors, MessageId.RSC_005, MessageId.RSC_005); + Collections.addAll(expectedErrors, MessageId.RSC_005); + Collections.addAll(expectedFatals, MessageId.RSC_016); retrieveData("valueWithoutQuotes.opf"); } diff --git a/src/test/resources/epub3/03-resources/resources.feature b/src/test/resources/epub3/03-resources/resources.feature index 135985cd2..9ce586246 100644 --- a/src/test/resources/epub3/03-resources/resources.feature +++ b/src/test/resources/epub3/03-resources/resources.feature @@ -392,14 +392,12 @@ Scenario: a not well-formed Package Document is reported When checking file 'conformance-xml-malformed-error.opf' Then fatal error RSC-016 is reported (parsing error) - And error RSC-005 is reported (schema error) And no other errors or warnings are reported @spec @xref:sec-xml-constraint Scenario: using a not-declared namespace is not allowed When checking file 'conformance-xml-undeclared-namespace-error.opf' Then fatal error RSC-016 is reported (parsing error) - And error RSC-005 is reported (schema error) And no other errors or warnings are reported Scenario: Verify an attribute value with leading/trailing whitespace is allowed (issue 332) diff --git a/src/test/resources/epub3/06-content-document/content-document-xhtml.feature b/src/test/resources/epub3/06-content-document/content-document-xhtml.feature index d00ad4a86..e81512ece 100644 --- a/src/test/resources/epub3/06-content-document/content-document-xhtml.feature +++ b/src/test/resources/epub3/06-content-document/content-document-xhtml.feature @@ -91,14 +91,12 @@ Feature: EPUB 3 — Content Documents — XHTML Scenario: Report entity references not ending with a semicolon When checking document 'entities-no-semicolon-error.xhtml' Then fatal error RSC-016 is reported - And error RSC-005 is reported And the message contains 'must end with the \';\' delimiter' And no other errors or warnings are reported Scenario: Report unknown entity references When checking document 'entities-unknown-error.xhtml' Then fatal error RSC-016 is reported - And error RSC-005 is reported And the message contains 'was referenced, but not declared' And no other errors or warnings are reported