Issue #19815: Fix segfault when parsing empty namespace declaration.
Based on patches by Christian Heimes and Vajrasky Kok
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index adb7852..9fb6c99 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -713,14 +713,21 @@
end {namespace}root
end-ns None
+ >>> import StringIO
+
+ >>> events = ('start-ns', 'end-ns')
+ >>> context = ET.iterparse(StringIO.StringIO(r"<root xmlns=''/>"), events)
+ >>> for action, elem in context:
+ ... print action, elem
+ start-ns ('', '')
+ end-ns None
+
>>> events = ("start", "end", "bogus")
>>> with open(SIMPLE_XMLFILE, "rb") as f:
... iterparse(f, events)
Traceback (most recent call last):
ValueError: unknown event 'bogus'
- >>> import StringIO
-
>>> source = StringIO.StringIO(
... "<?xml version='1.0' encoding='iso-8859-1'?>\\n"
... "<body xmlns='http://éffbot.org/ns'\\n"
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index b9abcac..2a7c828 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -2338,7 +2338,10 @@
PyObject* sprefix = NULL;
PyObject* suri = NULL;
- suri = makestring(uri, strlen(uri));
+ if (uri)
+ suri = makestring(uri, strlen(uri));
+ else
+ suri = PyString_FromStringAndSize("", 0);
if (!suri)
return;