summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorscoder <stefan_ml@behnel.de>2017-09-14 20:00:03 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-09-14 20:00:03 (GMT)
commitc8d8e15bfc24abeeaaf3d8be9073276b0c011cdf (patch)
treefb00b03ee188ead7d74c74d8042b4c966cfeeaa3 /Lib/test
parent0b3a87ef54a0112b74e8a1d8c6f87d10db4239ab (diff)
downloadcpython-c8d8e15bfc24abeeaaf3d8be9073276b0c011cdf.zip
cpython-c8d8e15bfc24abeeaaf3d8be9073276b0c011cdf.tar.gz
cpython-c8d8e15bfc24abeeaaf3d8be9073276b0c011cdf.tar.bz2
bpo-31455: Fix an assertion failure in ElementTree.XMLParser(). (#3545)
* Avoid calling "PyObject_GetAttrString()" (and potentially executing user code) with a live exception set. * Ignore only AttributeError on attribute lookups in ElementTree.XMLParser() and propagate all other exceptions.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_xml_etree.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index 233b4da..baa4e1f 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -2498,6 +2498,31 @@ class TreeBuilderTest(unittest.TestCase):
('html', '-//W3C//DTD XHTML 1.0 Transitional//EN',
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'))
+ def test_builder_lookup_errors(self):
+ class RaisingBuilder:
+ def __init__(self, raise_in=None, what=ValueError):
+ self.raise_in = raise_in
+ self.what = what
+
+ def __getattr__(self, name):
+ if name == self.raise_in:
+ raise self.what(self.raise_in)
+ def handle(*args):
+ pass
+ return handle
+
+ ET.XMLParser(target=RaisingBuilder())
+ # cET also checks for 'close' and 'doctype', PyET does it only at need
+ for event in ('start', 'data', 'end', 'comment', 'pi'):
+ with self.assertRaisesRegex(ValueError, event):
+ ET.XMLParser(target=RaisingBuilder(event))
+
+ ET.XMLParser(target=RaisingBuilder(what=AttributeError))
+ for event in ('start', 'data', 'end', 'comment', 'pi'):
+ parser = ET.XMLParser(target=RaisingBuilder(event, what=AttributeError))
+ parser.feed(self.sample1)
+ self.assertIsNone(parser.close())
+
class XMLParserTest(unittest.TestCase):
sample1 = b'<file><line>22</line></file>'