diff --git a/ChangeLog b/ChangeLog index 221f4de6..a82a3d38 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Tue Dec 31 15:44:02 CET 2002 Daniel Veillard + + * xmlreader.c python/tests/reader2.py: fixed a problem with + validation within entities pointed by Stéphane Bidoul, augmented + the tests to catch those. + Tue Dec 31 12:15:37 CET 2002 Daniel Veillard * python/generator.py: modified the generator to allow keeping diff --git a/python/tests/reader2.py b/python/tests/reader2.py index 82e46bd6..ea2f782d 100755 --- a/python/tests/reader2.py +++ b/python/tests/reader2.py @@ -5,6 +5,7 @@ import sys import glob import string +import StringIO import libxml2 # Memory debug specific @@ -43,6 +44,58 @@ for file in valid_files: if err != expect: print err +# +# another separate test based on Stephane Bidoul one +# +s = """ + + + + +xxx"> +]> + + &x; + bbb + +""" +expect="""1,test +3,#text +1,x +1,c +3,#text +15,c +15,x +3,#text +1,b +3,#text +15,b +3,#text +15,test +""" +res="" +err="" + +input = libxml2.inputBuffer(StringIO.StringIO(s)) +reader = input.newTextReader("test2") +reader.SetParserProp(libxml2.PARSER_LOADDTD,1) +reader.SetParserProp(libxml2.PARSER_DEFAULTATTRS,1) +reader.SetParserProp(libxml2.PARSER_SUBST_ENTITIES,1) +reader.SetParserProp(libxml2.PARSER_VALIDATE,1) +while reader.Read() == 1: + res = res + "%s,%s\n" % (reader.NodeType(),reader.Name()) + +if res != expect: + print "test2 failed: unexpected output" + print res + sys.exit(1) +if err != "": + print "test2 failed: validation error found" + print err + sys.exit(1) + +del input del reader # Memory debug specific diff --git a/xmlreader.c b/xmlreader.c index a65a1bf2..7c04a0e9 100644 --- a/xmlreader.c +++ b/xmlreader.c @@ -134,16 +134,21 @@ static void xmlTextReaderStartElement(void *ctx, const xmlChar *fullname, const xmlChar **atts) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; + xmlParserCtxtPtr origctxt; xmlTextReaderPtr reader = ctxt->_private; #ifdef DEBUG_CALLBACKS printf("xmlTextReaderStartElement(%s)\n", fullname); #endif if ((reader != NULL) && (reader->startElement != NULL)) { + /* + * when processing an entity, the context may have been changed + */ + origctxt = reader->ctxt; reader->startElement(ctx, fullname, atts); - if (ctxt->validate) { - ctxt->valid &= xmlValidatePushElement(&ctxt->vctxt, ctxt->myDoc, - ctxt->node, fullname); + if (origctxt->validate) { + ctxt->valid &= xmlValidatePushElement(&origctxt->vctxt, + ctxt->myDoc, ctxt->node, fullname); } } reader->state = XML_TEXTREADER_ELEMENT; @@ -159,6 +164,7 @@ xmlTextReaderStartElement(void *ctx, const xmlChar *fullname, static void xmlTextReaderEndElement(void *ctx, const xmlChar *fullname) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; + xmlParserCtxtPtr origctxt; xmlTextReaderPtr reader = ctxt->_private; #ifdef DEBUG_CALLBACKS @@ -166,12 +172,16 @@ xmlTextReaderEndElement(void *ctx, const xmlChar *fullname) { #endif if ((reader != NULL) && (reader->endElement != NULL)) { xmlNodePtr node = ctxt->node; + /* + * when processing an entity, the context may have been changed + */ + origctxt = reader->ctxt; reader->endElement(ctx, fullname); - if (ctxt->validate) { - ctxt->valid &= xmlValidatePopElement(&ctxt->vctxt, ctxt->myDoc, - node, fullname); + if (origctxt->validate) { + ctxt->valid &= xmlValidatePopElement(&origctxt->vctxt, + ctxt->myDoc, node, fullname); } } if (reader->state == XML_TEXTREADER_ELEMENT) @@ -192,6 +202,7 @@ static void xmlTextReaderCharacters(void *ctx, const xmlChar *ch, int len) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; + xmlParserCtxtPtr origctxt; xmlTextReaderPtr reader = ctxt->_private; #ifdef DEBUG_CALLBACKS @@ -199,9 +210,13 @@ xmlTextReaderCharacters(void *ctx, const xmlChar *ch, int len) #endif if ((reader != NULL) && (reader->characters != NULL)) { reader->characters(ctx, ch, len); + /* + * when processing an entity, the context may have been changed + */ + origctxt = reader->ctxt; - if (ctxt->validate) { - ctxt->valid &= xmlValidatePushCData(&ctxt->vctxt, ch, len); + if (origctxt->validate) { + ctxt->valid &= xmlValidatePushCData(&origctxt->vctxt, ch, len); } } }