Commit 67245a6e authored by Martin v. Löwis's avatar Martin v. Löwis

Issue #14168: Check for presence of _attrs before accessing it.

parent f1c42599
...@@ -362,11 +362,17 @@ class MinidomTest(unittest.TestCase): ...@@ -362,11 +362,17 @@ class MinidomTest(unittest.TestCase):
def testGetAttrList(self): def testGetAttrList(self):
pass 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): def testGetAttributeNS(self):
dom = Document() dom = Document()
...@@ -378,6 +384,9 @@ class MinidomTest(unittest.TestCase): ...@@ -378,6 +384,9 @@ class MinidomTest(unittest.TestCase):
'http://www.python.org') 'http://www.python.org')
self.assertEqual(child.getAttributeNS("http://www.w3.org", "other"), 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 def testGetAttributeNode(self): pass
......
...@@ -723,12 +723,16 @@ class Element(Node): ...@@ -723,12 +723,16 @@ class Element(Node):
Node.unlink(self) Node.unlink(self)
def getAttribute(self, attname): def getAttribute(self, attname):
if self._attrs is None:
return ""
try: try:
return self._attrs[attname].value return self._attrs[attname].value
except KeyError: except KeyError:
return "" return ""
def getAttributeNS(self, namespaceURI, localName): def getAttributeNS(self, namespaceURI, localName):
if self._attrsNS is None:
return ""
try: try:
return self._attrsNS[(namespaceURI, localName)].value return self._attrsNS[(namespaceURI, localName)].value
except KeyError: except KeyError:
......
...@@ -511,6 +511,8 @@ Core and Builtins ...@@ -511,6 +511,8 @@ Core and Builtins
Library Library
------- -------
- Issue #14168: Check for presence of _attrs before accessing it.
- Issue #14195: An issue that caused weakref.WeakSet instances to incorrectly - 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 return True for a WeakSet instance 'a' in both 'a < a' and 'a > a' has been
fixed. fixed.
......
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