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 5351b0b..89971f1 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -526,6 +526,11 @@
('end-ns', None),
])
+ events = ('start-ns', 'end-ns')
+ context = iterparse(io.StringIO(r"<root xmlns=''/>"), events)
+ res = [action for action, elem in context]
+ self.assertEqual(res, ['start-ns', 'end-ns'])
+
events = ("start", "end", "bogus")
with self.assertRaises(ValueError) as cm:
with open(SIMPLE_XMLFILE, "rb") as f:
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 46a1f41..b3b6976 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -3038,7 +3038,10 @@
if (PyErr_Occurred())
return;
- suri = PyUnicode_DecodeUTF8(uri, strlen(uri), "strict");
+ if (uri)
+ suri = PyUnicode_DecodeUTF8(uri, strlen(uri), "strict");
+ else
+ suri = PyUnicode_FromString("");
if (!suri)
return;