diff -r 6478c4259ce3 Lib/test/test_xml_etree.py --- a/Lib/test/test_xml_etree.py Thu Jan 10 07:46:29 2013 +0200 +++ b/Lib/test/test_xml_etree.py Thu Jan 10 11:03:17 2013 +0200 @@ -1863,6 +1863,10 @@ tree = ET.ElementTree(None) self.assertRaises(AttributeError, tree.iter) + # Issue #16913 + doc = ET.XML("a&b&c&") + self.assertEqual(''.join(doc.itertext()), 'a&b&c&') + def test_corners(self): # single root, no subelements a = ET.Element('a') diff -r 6478c4259ce3 Modules/_elementtree.c --- a/Modules/_elementtree.c Thu Jan 10 07:46:29 2013 +0200 +++ b/Modules/_elementtree.c Thu Jan 10 11:03:17 2013 +0200 @@ -1845,7 +1845,9 @@ PyObject_RichCompareBool(it->root_element->tag, it->sought_tag, Py_EQ) == 1) { if (it->gettext) { - PyObject *text = JOIN_OBJ(it->root_element->text); + PyObject *text = element_get_text(it->root_element); + if (!text) + return NULL; if (PyObject_IsTrue(text)) { Py_INCREF(text); return text; @@ -1875,7 +1877,9 @@ } if (it->gettext) { - PyObject *text = JOIN_OBJ(child->text); + PyObject *text = element_get_text(child); + if (!text) + return NULL; if (PyObject_IsTrue(text)) { Py_INCREF(text); return text; @@ -1890,8 +1894,15 @@ continue; } else { - PyObject *tail = it->gettext ? JOIN_OBJ(cur_parent->tail) : Py_None; + PyObject *tail; ParentLocator *next = it->parent_stack->next; + if (it->gettext) { + tail = element_get_tail(cur_parent); + if (!tail) + return NULL; + } + else + tail = Py_None; Py_XDECREF(it->parent_stack->parent); PyObject_Free(it->parent_stack); it->parent_stack = next;