Re: [xml] PEReferences - tricky and error-prone



Hi Daniel,

See attached a patch to handle my original example.

It works by combining three effects:

- always call SKIP_BLANKS before and after the '%'
in  xmlParseEntityDecl

- postpone switching from XML_PARSER_DTD to 
XML_PARSER_ENTITY_DECL in xmlParseEntityDecl

- ignoring '%' followed by whitespace in xmlParserHandlePEReference

After this is now O.K., the second example (leaving out the spaces
around %percent;) works as intended, i.e. to test whether libxml2
inserts spaces before and after the replacement text.

If I interpret the output right, there is no space inserted after
the replacement text, and therefore the second example is
judged not valid by libxml2. If it should be valid, another patch
is to be done.

Regards,
Peter Jacobi


*** parser.c.orig       Fri May 31 11:08:18 2002
--- parser.c    Mon Jun 03 17:14:55 2002
***************
*** 765,775 ****
             */
            if ((ctxt->external == 0) && (ctxt->inputNr == 1))
                return;
              break;
          case XML_PARSER_IGNORE:
              return;
      }
- 
      NEXT;
      name = xmlParseName(ctxt);
      if (xmlParserDebugEntities)
--- 759,770 ----
             */
            if ((ctxt->external == 0) && (ctxt->inputNr == 1))
                return;
+           if (IS_BLANK(NXT(1)) || NXT(1) == 0)
+               return;
              break;
          case XML_PARSER_IGNORE:
              return;
      }
      NEXT;
      name = xmlParseName(ctxt);
      if (xmlParserDebugEntities)
***************
*** 3383,3388 ****
--- 3338,3344 ----
      xmlChar *ndata = NULL;
      int isParameter = 0;
      xmlChar *orig = NULL;
+     int skipped = 0;
      
      GROW;
      if ((RAW == '<') && (NXT(1) == '!') &&
***************
*** 3390,3399 ****
          (NXT(4) == 'T') && (NXT(5) == 'I') &&
          (NXT(6) == 'T') && (NXT(7) == 'Y')) {
        xmlParserInputPtr input = ctxt->input;
-       ctxt->instate = XML_PARSER_ENTITY_DECL;
        SHRINK;
        SKIP(8);
!       if (!IS_BLANK(CUR)) {
            ctxt->errNo = XML_ERR_SPACE_REQUIRED;
            if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
                ctxt->sax->error(ctxt->userData,
--- 3346,3355 ----
          (NXT(4) == 'T') && (NXT(5) == 'I') &&
          (NXT(6) == 'T') && (NXT(7) == 'Y')) {
        xmlParserInputPtr input = ctxt->input;
        SHRINK;
        SKIP(8);
!       skipped = SKIP_BLANKS;
!       if (skipped == 0) {
            ctxt->errNo = XML_ERR_SPACE_REQUIRED;
            if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
                ctxt->sax->error(ctxt->userData,
***************
*** 3401,3411 ****
            ctxt->wellFormed = 0;
            ctxt->disableSAX = 1;
        }
-       SKIP_BLANKS;
  
        if (RAW == '%') {
            NEXT;
!           if (!IS_BLANK(CUR)) {
                ctxt->errNo = XML_ERR_SPACE_REQUIRED;
                if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
                    ctxt->sax->error(ctxt->userData,
--- 3357,3367 ----
            ctxt->wellFormed = 0;
            ctxt->disableSAX = 1;
        }
  
        if (RAW == '%') {
            NEXT;
!           skipped = SKIP_BLANKS;
!           if (skipped == 0) {
                ctxt->errNo = XML_ERR_SPACE_REQUIRED;
                if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
                    ctxt->sax->error(ctxt->userData,
***************
*** 3413,3421 ****
                ctxt->wellFormed = 0;
                ctxt->disableSAX = 1;
            }
-           SKIP_BLANKS;
            isParameter = 1;
        }
  
          name = xmlParseName(ctxt);
        if (name == NULL) {
--- 3369,3377 ----
                ctxt->wellFormed = 0;
                ctxt->disableSAX = 1;
            }
            isParameter = 1;
        }
+       ctxt->instate = XML_PARSER_ENTITY_DECL;
  
          name = xmlParseName(ctxt);
        if (name == NULL) {



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