[xml] pre 2.7 sax behavior



Apologies if this comes through twice. Originally sent from a different email address.

Attached is patch to provide pre 2.7 entity processing behavior when setting an XML_PARSE_OLDSAX option on the parser context. The changes in entity processing made in 2.7 cause some serious breakage in the PHP SAX processor and no other alternative exists to fix this problem without libxml2 supporting the old behavior. In order not to degrade performance, this option is disabled by default.

Please let me know if anyone has or sees any issues with this patch?

Thanks,

Rob


Index: include/libxml/parser.h
===================================================================
--- include/libxml/parser.h     (revision 3804)
+++ include/libxml/parser.h     (working copy)
@@ -1096,7 +1096,8 @@
                                   crash if you try to modify the tree) */
     XML_PARSE_OLD10    = 1<<17,/* parse using XML-1.0 before update 5 */
     XML_PARSE_NOBASEFIX = 1<<18,/* do not fixup XINCLUDE xml:base uris */
-    XML_PARSE_HUGE      = 1<<19 /* relax any hardcoded limit from the parser */
+    XML_PARSE_HUGE      = 1<<19, /* relax any hardcoded limit from the parser */
+    XML_PARSE_OLDSAX    = 1<<20,/* parse using SAX2 interface from before 2.7.0 */
 } xmlParserOption;
 
 XMLPUBFUN void XMLCALL
Index: parser.c
===================================================================
--- parser.c    (revision 3804)
+++ parser.c    (working copy)
@@ -7047,9 +7047,11 @@
     /*
      * Predefined entites override any extra definition
      */
-    ent = xmlGetPredefinedEntity(name);
-    if (ent != NULL)
-        return(ent);
+    if ((ctxt->options & XML_PARSE_OLDSAX) == 0) {
+        ent = xmlGetPredefinedEntity(name);
+        if (ent != NULL)
+            return(ent);
+    }
 
     /*
      * Increate the number of entity references parsed
@@ -7063,6 +7065,9 @@
     if (ctxt->sax != NULL) {
        if (ctxt->sax->getEntity != NULL)
            ent = ctxt->sax->getEntity(ctxt->userData, name);
+       if ((ctxt->wellFormed == 1 ) && (ent == NULL) && 
+           (ctxt->options & XML_PARSE_OLDSAX))
+           ent = xmlGetPredefinedEntity(name);
        if ((ctxt->wellFormed == 1 ) && (ent == NULL) &&
            (ctxt->userData==ctxt)) {
            ent = xmlSAX2GetEntity(ctxt, name);
@@ -7135,6 +7140,7 @@
      */
     else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) &&
             (ent != NULL) && (ent->content != NULL) &&
+            (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) &&
             (xmlStrchr(ent->content, '<'))) {
        xmlFatalErrMsgStr(ctxt, XML_ERR_LT_IN_ATTRIBUTE,
     "'<' in entity '%s' is not allowed in attributes values\n", name);
@@ -7231,11 +7237,13 @@
     /*
      * Predefined entites override any extra definition
      */
-    ent = xmlGetPredefinedEntity(name);
-    if (ent != NULL) {
-        xmlFree(name);
-        *str = ptr;
-        return(ent);
+    if ((ctxt->options & XML_PARSE_OLDSAX) == 0) {
+        ent = xmlGetPredefinedEntity(name);
+        if (ent != NULL) {
+            xmlFree(name);
+            *str = ptr;
+            return(ent);
+        }
     }
 
     /*
@@ -7250,6 +7258,8 @@
     if (ctxt->sax != NULL) {
        if (ctxt->sax->getEntity != NULL)
            ent = ctxt->sax->getEntity(ctxt->userData, name);
+       if ((ent == NULL) && (ctxt->options & XML_PARSE_OLDSAX))
+           ent = xmlGetPredefinedEntity(name);
        if ((ent == NULL) && (ctxt->userData==ctxt)) {
            ent = xmlSAX2GetEntity(ctxt, name);
        }
@@ -7318,6 +7328,7 @@
      */
     else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) &&
             (ent != NULL) && (ent->content != NULL) &&
+            (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) &&
             (xmlStrchr(ent->content, '<'))) {
        xmlFatalErrMsgStr(ctxt, XML_ERR_LT_IN_ATTRIBUTE,
      "'<' in entity '%s' is not allowed in attributes values\n",
@@ -14211,6 +14222,10 @@
        ctxt->options |= XML_PARSE_HUGE;
         options -= XML_PARSE_HUGE;
     }
+    if (options & XML_PARSE_OLDSAX) {
+       ctxt->options |= XML_PARSE_OLDSAX;
+        options -= XML_PARSE_OLDSAX;
+    }
     ctxt->linenumbers = 1;
     return (options);
 }


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