[libxml2] Simplify handling of parameter entity references



commit aa267cd12752f2ff94b0f0c01e2adc30a7913ad4
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Sun Jun 18 23:29:51 2017 +0200

    Simplify handling of parameter entity references
    
    There are only two places where parameter entity references must be
    handled. For the internal subset in xmlParseInternalSubset. For the
    external subset or content from other external PEs in xmlSkipBlankChars.
    
    Make sure that xmlSkipBlankChars skips over sequences of PEs and
    whitespace. Rely on xmlSkipBlankChars instead of calling
    xmlParsePEReference directly when in the external subset or a
    conditional section.
    
    xmlParserHandlePEReference is unused now.

 parser.c          |   56 +++++++++++++++++++---------------------------------
 parserInternals.c |    2 -
 2 files changed, 21 insertions(+), 37 deletions(-)
---
diff --git a/parser.c b/parser.c
index 2bad113..e7efdce 100644
--- a/parser.c
+++ b/parser.c
@@ -2043,7 +2043,6 @@ static int spacePop(xmlParserCtxtPtr ctxt) {
 
 #define SKIP(val) do {                                                 \
     ctxt->nbChars += (val),ctxt->input->cur += (val),ctxt->input->col+=(val);                  \
-    if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt);    \
     if ((*ctxt->input->cur == 0) &&                                    \
         (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0))           \
            xmlPopInput(ctxt);                                          \
@@ -2058,7 +2057,6 @@ static int spacePop(xmlParserCtxtPtr ctxt) {
        ctxt->nbChars++;                                                \
        ctxt->input->cur++;                                             \
     }                                                                  \
-    if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt);    \
     if ((*ctxt->input->cur == 0) &&                                    \
         (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0))           \
            xmlPopInput(ctxt);                                          \
@@ -2170,26 +2168,27 @@ xmlSkipBlankChars(xmlParserCtxtPtr ctxt) {
        }
        ctxt->input->cur = cur;
     } else {
-       int cur;
-       do {
-           cur = CUR;
-           while ((IS_BLANK_CH(cur) && /* CHECKED tstblanks.xml */
-                  (ctxt->instate != XML_PARSER_EOF))) {
+        int expandPE = ((ctxt->external != 0) || (ctxt->inputNr != 1));
+
+       while (1) {
+            if (IS_BLANK_CH(CUR)) { /* CHECKED tstblanks.xml */
                NEXT;
-               cur = CUR;
                res++;
-           }
-           while ((cur == 0) && (ctxt->inputNr > 1) &&
-                  (ctxt->instate != XML_PARSER_COMMENT)) {
-               xmlPopInput(ctxt);
-               cur = CUR;
-           }
-           /*
-            * Need to handle support of entities branching here
-            */
-           if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt);
-       } while ((IS_BLANK(cur)) && /* CHECKED tstblanks.xml */
-                (ctxt->instate != XML_PARSER_EOF));
+           } else if (CUR == '%') {
+                /*
+                 * Need to handle support of entities branching here
+                 */
+               if ((expandPE == 0) || (IS_BLANK_CH(NXT(1))) || (NXT(1) == 0))
+                    break;
+               xmlParsePEReference(ctxt);
+            } else if (CUR == 0) {
+                if (ctxt->inputNr <= 1)
+                    break;
+                xmlPopInput(ctxt);
+            } else {
+                break;
+            }
+        }
     }
     return(res);
 }
@@ -6730,12 +6729,9 @@ xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
            const xmlChar *check = CUR_PTR;
            unsigned int cons = ctxt->input->consumed;
 
+            SKIP_BLANKS;
            if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) {
                xmlParseConditionalSections(ctxt);
-           } else if (IS_BLANK_CH(CUR)) {
-               NEXT;
-           } else if (RAW == '%') {
-               xmlParsePEReference(ctxt);
            } else
                xmlParseMarkupDecl(ctxt);
 
@@ -6907,13 +6903,6 @@ xmlParseMarkupDecl(xmlParserCtxtPtr ctxt) {
         return;
 
     /*
-     * This is only for internal subset. On external entities,
-     * the replacement is done before parsing stage
-     */
-    if ((ctxt->external == 0) && (ctxt->inputNr == 1))
-       xmlParsePEReference(ctxt);
-
-    /*
      * Conditional sections are allowed from entities included
      * by PE References in the internal subset.
      */
@@ -7060,13 +7049,10 @@ xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xmlChar *ExternalID,
        const xmlChar *check = CUR_PTR;
        unsigned int cons = ctxt->input->consumed;
 
+        SKIP_BLANKS;
        GROW;
         if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) {
            xmlParseConditionalSections(ctxt);
-       } else if (IS_BLANK_CH(CUR)) {
-           NEXT;
-       } else if (RAW == '%') {
-            xmlParsePEReference(ctxt);
        } else
            xmlParseMarkupDecl(ctxt);
 
diff --git a/parserInternals.c b/parserInternals.c
index c3300ae..7593fc7 100644
--- a/parserInternals.c
+++ b/parserInternals.c
@@ -541,8 +541,6 @@ xmlNextChar(xmlParserCtxtPtr ctxt)
         if (*ctxt->input->cur == 0)
             xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
     }
-    if ((*ctxt->input->cur == '%') && (!ctxt->html))
-        xmlParserHandlePEReference(ctxt);
     if ((*ctxt->input->cur == 0) &&
         (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0))
         xmlPopInput(ctxt);


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