fixed another validity checking in external parsed entities raised by
* xmlreader.c python/tests/reader2.py: fixed another validity
checking in external parsed entities raised by Stéphane Bidoul
and added a specific regression test.
* python/tests/reader3.py: cleanup
Daniel
diff --git a/ChangeLog b/ChangeLog
index a82a3d3..4de7607 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Wed Jan 1 15:42:54 CET 2003 Daniel Veillard <daniel@veillard.com>
+
+ * xmlreader.c python/tests/reader2.py: fixed another validity
+ checking in external parsed entities raised by Stéphane Bidoul
+ and added a specific regression test.
+ * python/tests/reader3.py: cleanup
+
Tue Dec 31 15:44:02 CET 2002 Daniel Veillard <daniel@veillard.com>
* xmlreader.c python/tests/reader2.py: fixed a problem with
diff --git a/python/tests/reader2.py b/python/tests/reader2.py
index ea2f782..2be89e2 100755
--- a/python/tests/reader2.py
+++ b/python/tests/reader2.py
@@ -95,6 +95,58 @@
print err
sys.exit(1)
+#
+# Another test for external entity parsing and validation
+#
+
+s = """<!DOCTYPE test [
+<!ELEMENT test (x)>
+<!ELEMENT x (#PCDATA)>
+<!ENTITY e SYSTEM "tst.ent">
+]>
+<test>
+ &e;
+</test>
+"""
+tst_ent = """<x>hello</x>"""
+expect="""1 test
+3 #text
+1 x
+3 #text
+15 x
+3 #text
+15 test
+"""
+res=""
+
+def myResolver(URL, ID, ctxt):
+ if URL == "tst.ent":
+ return(StringIO.StringIO(tst_ent))
+ return None
+
+libxml2.setEntityLoader(myResolver)
+
+input = libxml2.inputBuffer(StringIO.StringIO(s))
+reader = input.newTextReader("test3")
+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 "test3 failed: unexpected output"
+ print res
+ sys.exit(1)
+if err != "":
+ print "test3 failed: validation error found"
+ print err
+ sys.exit(1)
+
+#
+# cleanup
+#
del input
del reader
diff --git a/python/tests/reader3.py b/python/tests/reader3.py
index 1593afb..1affbe9 100755
--- a/python/tests/reader3.py
+++ b/python/tests/reader3.py
@@ -94,6 +94,9 @@
print "test_noent: Error detecting the end"
sys.exit(1)
+#
+# cleanup
+#
del f
del input
del reader
diff --git a/xmlreader.c b/xmlreader.c
index 7c04a0e..fea78cb 100644
--- a/xmlreader.c
+++ b/xmlreader.c
@@ -151,7 +151,8 @@
ctxt->myDoc, ctxt->node, fullname);
}
}
- reader->state = XML_TEXTREADER_ELEMENT;
+ if (reader != NULL)
+ reader->state = XML_TEXTREADER_ELEMENT;
}
/**
@@ -184,10 +185,12 @@
ctxt->myDoc, node, fullname);
}
}
- if (reader->state == XML_TEXTREADER_ELEMENT)
- reader->wasempty = 1;
- else
- reader->wasempty = 0;
+ if (reader != NULL) {
+ if (reader->state == XML_TEXTREADER_ELEMENT)
+ reader->wasempty = 1;
+ else
+ reader->wasempty = 0;
+ }
}
/**