]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-96175: add missing self._localName assignment in `xml.dom.minidom.Attr` (#96176)
authorKevin Kirsche <Kev.Kirsche+GitHub@gmail.com>
Tue, 23 Aug 2022 16:16:02 +0000 (12:16 -0400)
committerGitHub <noreply@github.com>
Tue, 23 Aug 2022 16:16:02 +0000 (09:16 -0700)
X-Ref: https://github.com/python/typeshed/pull/8590#discussion_r951473977

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Lib/test/test_minidom.py
Lib/xml/dom/minidom.py
Misc/NEWS.d/next/Library/2022-08-22-13-54-20.gh-issue-96175.bH7zGU.rst [new file with mode: 0644]

index 97620258d82f6ba9b1d8c93a1db231a29b1a25d1..ef38c362103fc6c43245b34ab5e503b687f78fd0 100644 (file)
@@ -9,7 +9,7 @@ import unittest
 import pyexpat
 import xml.dom.minidom
 
-from xml.dom.minidom import parse, Node, Document, parseString
+from xml.dom.minidom import parse, Attr, Node, Document, parseString
 from xml.dom.minidom import getDOMImplementation
 from xml.parsers.expat import ExpatError
 
@@ -77,6 +77,20 @@ class MinidomTest(unittest.TestCase):
             dom.unlink()
             self.confirm(isinstance(dom, Document))
 
+    def testAttrModeSetsParamsAsAttrs(self):
+        attr = Attr("qName", "namespaceURI", "localName", "prefix")
+        self.assertEqual(attr.name, "qName")
+        self.assertEqual(attr.namespaceURI, "namespaceURI")
+        self.assertEqual(attr.prefix, "prefix")
+        self.assertEqual(attr.localName, "localName")
+
+    def testAttrModeSetsNonOptionalAttrs(self):
+        attr = Attr("qName", "namespaceURI", None, "prefix")
+        self.assertEqual(attr.name, "qName")
+        self.assertEqual(attr.namespaceURI, "namespaceURI")
+        self.assertEqual(attr.prefix, "prefix")
+        self.assertEqual(attr.localName, attr.name)
+
     def testGetElementsByTagName(self):
         dom = parse(tstfile)
         self.confirm(dom.getElementsByTagName("LI") == \
index d09ef5e7d0371ae3e7c6d56fb89faf8bb401bc49..ef8a159833bbc07672cd3a17a3e49943a97c85e1 100644 (file)
@@ -358,6 +358,8 @@ class Attr(Node):
         self._name = qName
         self.namespaceURI = namespaceURI
         self._prefix = prefix
+        if localName is not None:
+            self._localName = localName
         self.childNodes = NodeList()
 
         # Add the single child node that represents the value of the attr
diff --git a/Misc/NEWS.d/next/Library/2022-08-22-13-54-20.gh-issue-96175.bH7zGU.rst b/Misc/NEWS.d/next/Library/2022-08-22-13-54-20.gh-issue-96175.bH7zGU.rst
new file mode 100644 (file)
index 0000000..c34eff2
--- /dev/null
@@ -0,0 +1 @@
+Fix unused ``localName`` parameter in the ``Attr`` class in :mod:`xml.dom.minidom`.