From 67245a6ed4a5e36584e5b6d9f0dd5ee4e42d65b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Mon, 5 Mar 2012 07:01:49 +0100 Subject: Issue #14168: Check for presence of _attrs before accessing it. --- Lib/test/test_minidom.py | 15 ++++++++++++--- Lib/xml/dom/minidom.py | 4 ++++ Misc/NEWS | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py index 752a840..cc4c95b 100644 --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -362,11 +362,17 @@ class MinidomTest(unittest.TestCase): def testGetAttrList(self): pass - def testGetAttrValues(self): pass + def testGetAttrValues(self): + pass - def testGetAttrLength(self): pass + def testGetAttrLength(self): + pass - def testGetAttribute(self): pass + def testGetAttribute(self): + dom = Document() + child = dom.appendChild( + dom.createElementNS("http://www.python.org", "python:abc")) + self.assertEqual(child.getAttribute('missing'), '') def testGetAttributeNS(self): dom = Document() @@ -378,6 +384,9 @@ class MinidomTest(unittest.TestCase): 'http://www.python.org') self.assertEqual(child.getAttributeNS("http://www.w3.org", "other"), '') + child2 = child.appendChild(dom.createElement('abc')) + self.assertEqual(child2.getAttributeNS("http://www.python.org", "missing"), + '') def testGetAttributeNode(self): pass diff --git a/Lib/xml/dom/minidom.py b/Lib/xml/dom/minidom.py index 7e2f88e..3de8a4d 100644 --- a/Lib/xml/dom/minidom.py +++ b/Lib/xml/dom/minidom.py @@ -723,12 +723,16 @@ class Element(Node): Node.unlink(self) def getAttribute(self, attname): + if self._attrs is None: + return "" try: return self._attrs[attname].value except KeyError: return "" def getAttributeNS(self, namespaceURI, localName): + if self._attrsNS is None: + return "" try: return self._attrsNS[(namespaceURI, localName)].value except KeyError: diff --git a/Misc/NEWS b/Misc/NEWS index 386e6c0..532d2a8 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -511,6 +511,8 @@ Core and Builtins Library ------- +- Issue #14168: Check for presence of _attrs before accessing it. + - Issue #14195: An issue that caused weakref.WeakSet instances to incorrectly return True for a WeakSet instance 'a' in both 'a < a' and 'a > a' has been fixed. -- cgit v0.12