Commit 5dd40e55 authored by Eli Bendersky's avatar Eli Bendersky

Issue #19815: Fix segfault when parsing empty namespace declaration.

Based on patches by Christian Heimes and Vajrasky Kok
parent c303cfdb
......@@ -535,6 +535,11 @@ class ElementTreeTest(unittest.TestCase):
('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:
......
......@@ -2997,7 +2997,10 @@ expat_start_ns_handler(XMLParserObject* self, const XML_Char* prefix,
PyObject* sprefix = NULL;
PyObject* suri = NULL;
suri = PyUnicode_DecodeUTF8(uri, strlen(uri), "strict");
if (uri)
suri = PyUnicode_DecodeUTF8(uri, strlen(uri), "strict");
else
suri = PyUnicode_FromString("");
if (!suri)
return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment