]> granicus.if.org Git - python/commitdiff
SF#1534630
authorFredrik Lundh <fredrik@pythonware.com>
Wed, 16 Aug 2006 16:47:07 +0000 (16:47 +0000)
committerFredrik Lundh <fredrik@pythonware.com>
Wed, 16 Aug 2006 16:47:07 +0000 (16:47 +0000)
ignore data that arrives before the opening start tag

Lib/test/test_xml_etree_c.py
Modules/_elementtree.c

index 56e7fedfdc9b344ae3ba78a4c90f7e5e2d79e602..250f7910738e0587cef38e98efb70a00ded4efc9 100644 (file)
@@ -204,6 +204,17 @@ def check_encoding(encoding):
         "<?xml version='1.0' encoding='%s'?><xml />" % encoding
         )
 
+def bug_1534630():
+    """
+    >>> bob = ET.TreeBuilder()
+    >>> e = bob.data("data")
+    >>> e = bob.start("tag", {})
+    >>> e = bob.end("tag")
+    >>> e = bob.close()
+    >>> serialize(ET, e)
+    '<tag />'
+    """
+
 def test_main():
     from test import test_xml_etree_c
     test_support.run_doctest(test_xml_etree_c, verbosity=True)
index c9e524f74cfb42c30f2a4c456f19859b3be83c50..f21cf568561c4f1a324b61bb96f7515bee0b1437 100644 (file)
@@ -48,7 +48,7 @@
 
 #include "Python.h"
 
-#define VERSION "1.0.6-snapshot"
+#define VERSION "1.0.6"
 
 /* -------------------------------------------------------------------- */
 /* configuration */
@@ -1599,6 +1599,10 @@ LOCAL(PyObject*)
 treebuilder_handle_data(TreeBuilderObject* self, PyObject* data)
 {
     if (!self->data) {
+        if (self->last == (ElementObject*) Py_None) {
+            /* ignore calls to data before the first call to start */
+            Py_RETURN_NONE;
+        }
         /* store the first item as is */
         Py_INCREF(data); self->data = data;
     } else {