Repository: w3c/epubcheck
Pull request #1403 (2022-12-02 10:52:51)

fix: report fatal XML parsing errors only once as RSC-016


Patch:
diff --git a/src/main/java/com/adobe/epubcheck/xml/XMLParser.java b/src/main/java/com/adobe/epubcheck/xml/XMLParser.java
index 8e183ce7..6fd92409 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 class XMLParser
       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());
+      }
     }
   }
 


Test patch:
diff --git a/src/test/java/com/adobe/epubcheck/ocf/OPFPeekerTest.java b/src/test/java/com/adobe/epubcheck/ocf/OPFPeekerTest.java
index d1098db8..51bf5678 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 class OPFPeekerTest
   @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 135985cd..9ce58624 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 d00ad4a8..e81512ec 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