]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
#5762: fix handling of empty namespace in minidom, which would result in AttributeErr...
authorGeorg Brandl <georg@python.org>
Fri, 15 Oct 2010 17:58:45 +0000 (17:58 +0000)
committerGeorg Brandl <georg@python.org>
Fri, 15 Oct 2010 17:58:45 +0000 (17:58 +0000)
Lib/test/test_minidom.py
Lib/xml/dom/minidom.py
Misc/NEWS

index d9d3be49c843838c4e319c6244e0fc8ef81cfdaa..97668d343cbcef90bb446fb821bc0f5034112882 100644 (file)
@@ -1489,6 +1489,13 @@ class MinidomTest(unittest.TestCase):
         doc.appendChild(doc.createComment("foo--bar"))
         self.assertRaises(ValueError, doc.toxml)
 
+    def testEmptyXMLNSValue(self):
+        doc = parseString("<element xmlns=''>\n"
+                          "<foo/>\n</element>")
+        doc2 = parseString(doc.toxml())
+        self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE)
+
+
 def test_main():
     run_unittest(MinidomTest)
 
index 1beae0cffa52be0698120c16fcf6c0419c25b198..81a1330c603d05855214dc0696f230acb1781215 100644 (file)
@@ -301,9 +301,10 @@ def _in_document(node):
 
 def _write_data(writer, data):
     "Writes datachars to writer."
-    data = data.replace("&", "&amp;").replace("<", "&lt;")
-    data = data.replace("\"", "&quot;").replace(">", "&gt;")
-    writer.write(data)
+    if data:
+        data = data.replace("&", "&amp;").replace("<", "&lt;"). \
+                    replace("\"", "&quot;").replace(">", "&gt;")
+        writer.write(data)
 
 def _get_elements_by_tagName_helper(parent, name, rc):
     for node in parent.childNodes:
index 097edd20ee78b8847321d9fd2884a8b6ec378093..4bb89da9a6af16d8ec1f2ef7bb5b23865677b7a0 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -24,6 +24,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #5762: Fix AttributeError raised by ``xml.dom.minidom`` when an empty
+  XML namespace attribute is encountered.
+
 - Issue #2830: Add the ``html.escape()`` function, which quotes all problematic
   characters by default.  Deprecate ``cgi.escape()``.