Issue #18408: Fix _elementtree.c, don't call Python function from an expat
handler if a Python exception is set
This commit is contained in:
parent
ca713c014e
commit
3fd8cbd5e4
|
@ -2831,6 +2831,9 @@ expat_default_handler(XMLParserObject* self, const XML_Char* data_in,
|
||||||
if (data_len < 2 || data_in[0] != '&')
|
if (data_len < 2 || data_in[0] != '&')
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
return;
|
||||||
|
|
||||||
key = PyUnicode_DecodeUTF8(data_in + 1, data_len - 2, "strict");
|
key = PyUnicode_DecodeUTF8(data_in + 1, data_len - 2, "strict");
|
||||||
if (!key)
|
if (!key)
|
||||||
return;
|
return;
|
||||||
|
@ -2871,6 +2874,9 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in,
|
||||||
PyObject* attrib;
|
PyObject* attrib;
|
||||||
int ok;
|
int ok;
|
||||||
|
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
return;
|
||||||
|
|
||||||
/* tag name */
|
/* tag name */
|
||||||
tag = makeuniversal(self, tag_in);
|
tag = makeuniversal(self, tag_in);
|
||||||
if (!tag)
|
if (!tag)
|
||||||
|
@ -2929,6 +2935,9 @@ expat_data_handler(XMLParserObject* self, const XML_Char* data_in,
|
||||||
PyObject* data;
|
PyObject* data;
|
||||||
PyObject* res;
|
PyObject* res;
|
||||||
|
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
return;
|
||||||
|
|
||||||
data = PyUnicode_DecodeUTF8(data_in, data_len, "strict");
|
data = PyUnicode_DecodeUTF8(data_in, data_len, "strict");
|
||||||
if (!data)
|
if (!data)
|
||||||
return; /* parser will look for errors */
|
return; /* parser will look for errors */
|
||||||
|
@ -2952,6 +2961,9 @@ expat_end_handler(XMLParserObject* self, const XML_Char* tag_in)
|
||||||
PyObject* tag;
|
PyObject* tag;
|
||||||
PyObject* res = NULL;
|
PyObject* res = NULL;
|
||||||
|
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
return;
|
||||||
|
|
||||||
if (TreeBuilder_CheckExact(self->target))
|
if (TreeBuilder_CheckExact(self->target))
|
||||||
/* shortcut */
|
/* shortcut */
|
||||||
/* the standard tree builder doesn't look at the end tag */
|
/* the standard tree builder doesn't look at the end tag */
|
||||||
|
@ -2976,6 +2988,9 @@ expat_start_ns_handler(XMLParserObject* self, const XML_Char* prefix,
|
||||||
PyObject* sprefix = NULL;
|
PyObject* sprefix = NULL;
|
||||||
PyObject* suri = NULL;
|
PyObject* suri = NULL;
|
||||||
|
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
return;
|
||||||
|
|
||||||
suri = PyUnicode_DecodeUTF8(uri, strlen(uri), "strict");
|
suri = PyUnicode_DecodeUTF8(uri, strlen(uri), "strict");
|
||||||
if (!suri)
|
if (!suri)
|
||||||
return;
|
return;
|
||||||
|
@ -3000,6 +3015,9 @@ expat_start_ns_handler(XMLParserObject* self, const XML_Char* prefix,
|
||||||
static void
|
static void
|
||||||
expat_end_ns_handler(XMLParserObject* self, const XML_Char* prefix_in)
|
expat_end_ns_handler(XMLParserObject* self, const XML_Char* prefix_in)
|
||||||
{
|
{
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
return;
|
||||||
|
|
||||||
treebuilder_handle_namespace(
|
treebuilder_handle_namespace(
|
||||||
(TreeBuilderObject*) self->target, 0, NULL, NULL
|
(TreeBuilderObject*) self->target, 0, NULL, NULL
|
||||||
);
|
);
|
||||||
|
@ -3011,6 +3029,9 @@ expat_comment_handler(XMLParserObject* self, const XML_Char* comment_in)
|
||||||
PyObject* comment;
|
PyObject* comment;
|
||||||
PyObject* res;
|
PyObject* res;
|
||||||
|
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
return;
|
||||||
|
|
||||||
if (self->handle_comment) {
|
if (self->handle_comment) {
|
||||||
comment = PyUnicode_DecodeUTF8(comment_in, strlen(comment_in), "strict");
|
comment = PyUnicode_DecodeUTF8(comment_in, strlen(comment_in), "strict");
|
||||||
if (comment) {
|
if (comment) {
|
||||||
|
@ -3033,6 +3054,9 @@ expat_start_doctype_handler(XMLParserObject *self,
|
||||||
PyObject *parser_doctype = NULL;
|
PyObject *parser_doctype = NULL;
|
||||||
PyObject *res = NULL;
|
PyObject *res = NULL;
|
||||||
|
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
return;
|
||||||
|
|
||||||
doctype_name_obj = makeuniversal(self, doctype_name);
|
doctype_name_obj = makeuniversal(self, doctype_name);
|
||||||
if (!doctype_name_obj)
|
if (!doctype_name_obj)
|
||||||
return;
|
return;
|
||||||
|
@ -3101,6 +3125,9 @@ expat_pi_handler(XMLParserObject* self, const XML_Char* target_in,
|
||||||
PyObject* data;
|
PyObject* data;
|
||||||
PyObject* res;
|
PyObject* res;
|
||||||
|
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
return;
|
||||||
|
|
||||||
if (self->handle_pi) {
|
if (self->handle_pi) {
|
||||||
target = PyUnicode_DecodeUTF8(target_in, strlen(target_in), "strict");
|
target = PyUnicode_DecodeUTF8(target_in, strlen(target_in), "strict");
|
||||||
data = PyUnicode_DecodeUTF8(data_in, strlen(data_in), "strict");
|
data = PyUnicode_DecodeUTF8(data_in, strlen(data_in), "strict");
|
||||||
|
@ -3273,6 +3300,7 @@ expat_parse(XMLParserObject* self, const char* data, int data_len, int final)
|
||||||
{
|
{
|
||||||
int ok;
|
int ok;
|
||||||
|
|
||||||
|
assert(!PyErr_Occurred());
|
||||||
ok = EXPAT(Parse)(self->parser, data, data_len, final);
|
ok = EXPAT(Parse)(self->parser, data, data_len, final);
|
||||||
|
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred())
|
||||||
|
|
Loading…
Reference in New Issue