[libxml2] Don't use SAX1 if all element handlers are NULL



commit 99fc048d7f7292c5ee18e44c400bd73bc63a47ed
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Fri Aug 14 14:18:50 2020 +0200

    Don't use SAX1 if all element handlers are NULL
    
    Running xmllint with "--sax --noout" installs a SAX2 handler with all
    callbacks set to NULL. In this case or similar situations, we don't want
    to switch to SAX1 parsing.

 parser.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/parser.c b/parser.c
index f11ad51fe..be14c3228 100644
--- a/parser.c
+++ b/parser.c
@@ -1073,11 +1073,15 @@ xmlHasFeature(xmlFeature feature)
  */
 static void
 xmlDetectSAX2(xmlParserCtxtPtr ctxt) {
+    xmlSAXHandlerPtr sax;
     if (ctxt == NULL) return;
+    sax = ctxt->sax;
 #ifdef LIBXML_SAX1_ENABLED
-    if ((ctxt->sax) &&  (ctxt->sax->initialized == XML_SAX2_MAGIC) &&
-        ((ctxt->sax->startElementNs != NULL) ||
-         (ctxt->sax->endElementNs != NULL))) ctxt->sax2 = 1;
+    if ((sax) &&  (sax->initialized == XML_SAX2_MAGIC) &&
+        ((sax->startElementNs != NULL) ||
+         (sax->endElementNs != NULL) ||
+         ((sax->startElement == NULL) && (sax->endElement == NULL))))
+        ctxt->sax2 = 1;
 #else
     ctxt->sax2 = 1;
 #endif /* LIBXML_SAX1_ENABLED */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]