mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-29 11:41:22 +03:00
fixed a problem with validation within entities pointed by Stphane
* xmlreader.c python/tests/reader2.py: fixed a problem with validation within entities pointed by Stphane Bidoul, augmented the tests to catch those. Daniel
This commit is contained in:
@ -1,3 +1,9 @@
|
||||
Tue Dec 31 15:44:02 CET 2002 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* xmlreader.c python/tests/reader2.py: fixed a problem with
|
||||
validation within entities pointed by St<53>phane Bidoul, augmented
|
||||
the tests to catch those.
|
||||
|
||||
Tue Dec 31 12:15:37 CET 2002 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* python/generator.py: modified the generator to allow keeping
|
||||
|
@ -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 = """
|
||||
<!DOCTYPE test [
|
||||
<!ELEMENT test (x,b)>
|
||||
<!ELEMENT x (c)>
|
||||
<!ELEMENT b (#PCDATA)>
|
||||
<!ELEMENT c (#PCDATA)>
|
||||
<!ENTITY x "<x><c>xxx</c></x>">
|
||||
]>
|
||||
<test>
|
||||
&x;
|
||||
<b>bbb</b>
|
||||
</test>
|
||||
"""
|
||||
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
|
||||
|
31
xmlreader.c
31
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user