Commit f933e081 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 cf6a3e2a
...@@ -713,14 +713,21 @@ def iterparse(): ...@@ -713,14 +713,21 @@ def iterparse():
end {namespace}root end {namespace}root
end-ns None 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") >>> events = ("start", "end", "bogus")
>>> with open(SIMPLE_XMLFILE, "rb") as f: >>> with open(SIMPLE_XMLFILE, "rb") as f:
... iterparse(f, events) ... iterparse(f, events)
Traceback (most recent call last): Traceback (most recent call last):
ValueError: unknown event 'bogus' ValueError: unknown event 'bogus'
>>> import StringIO
>>> source = StringIO.StringIO( >>> source = StringIO.StringIO(
... "<?xml version='1.0' encoding='iso-8859-1'?>\\n" ... "<?xml version='1.0' encoding='iso-8859-1'?>\\n"
... "<body xmlns='http://&#233;ffbot.org/ns'\\n" ... "<body xmlns='http://&#233;ffbot.org/ns'\\n"
......
...@@ -2338,7 +2338,10 @@ expat_start_ns_handler(XMLParserObject* self, const XML_Char* prefix, ...@@ -2338,7 +2338,10 @@ expat_start_ns_handler(XMLParserObject* self, const XML_Char* prefix,
PyObject* sprefix = NULL; PyObject* sprefix = NULL;
PyObject* suri = NULL; PyObject* suri = NULL;
suri = makestring(uri, strlen(uri)); if (uri)
suri = makestring(uri, strlen(uri));
else
suri = PyString_FromStringAndSize("", 0);
if (!suri) if (!suri)
return; 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