This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2013年05月03日 19:56 by Aaron.Oakley, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| _elementtree.c-340a0.patch | Aaron.Oakley, 2013年05月03日 19:56 | Simple patch with test case | review | |
| Messages (3) | |||
|---|---|---|---|
| msg188326 - (view) | Author: Aaron Oakley (Aaron.Oakley) * | Date: 2013年05月03日 19:56 | |
When the _elementtree module is in use, the TreeBuilder class will raise an IndexError in treebuilder_handle_end if __init__ was passed "None".
I discovered this while writing a subclass of TreeBuilder with a modified __init__ method that delegated to TreeBuilder:
class MyTreeBuilder(ET.TreeBuilder):
def __init__(self, element_factory=None):
super().__init__(element_factory)
Used as a target, this class (and also simply "TreeBuilder(None)") will cause the IndexError when "parser.feed(data)" is called.
>>> import xml.etree.ElementTree as ET
>>> parser = ET.XMLParser(target=ET.TreeBuilder(None))
>>> parser.feed('<file><line>22</line></file>')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: pop from empty stack
The error is raised from treebuilder_handle_end, but the cause appears to be in treebuilder_handle_start.
if (self->element_factory) {
node = PyObject_CallFunction(self->element_factory, "OO", tag, attrib);
} else {
node = create_new_element(tag, attrib);
}
I included a patch adding a check against Py_None to the "if" test above which seems to fix the issue. I also included a simple test case for it.
|
|||
| msg189557 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2013年05月18日 22:48 | |
New changeset c430bea30457 by Eli Bendersky in branch '3.3': Issue #17901: fix TreeBuilder construction for an explicit element_factory=None http://hg.python.org/cpython/rev/c430bea30457 New changeset e79df5d1f680 by Eli Bendersky in branch 'default': Issue #17901: fix TreeBuilder construction for an explicit element_factory=None http://hg.python.org/cpython/rev/e79df5d1f680 |
|||
| msg189558 - (view) | Author: Eli Bendersky (eli.bendersky) * (Python committer) | Date: 2013年05月18日 22:49 | |
I committed a fix with a simplified test. Thanks for the contribution, Aaron. Also, to get your patches committed directly you need to sign the Python contributor agreement. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:45 | admin | set | github: 62101 |
| 2013年05月18日 22:49:26 | eli.bendersky | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2013年05月18日 22:49:10 | eli.bendersky | set | messages: + msg189558 |
| 2013年05月18日 22:48:04 | python-dev | set | nosy:
+ python-dev messages: + msg189557 |
| 2013年05月04日 15:40:08 | pitrou | set | nosy:
+ eli.bendersky stage: patch review |
| 2013年05月03日 19:56:56 | Aaron.Oakley | create | |