]> granicus.if.org Git - python/commitdiff
#12220: improve minidom error when URI contains spaces.
authorR David Murray <rdmurray@bitdance.com>
Sun, 20 Apr 2014 04:46:05 +0000 (00:46 -0400)
committerR David Murray <rdmurray@bitdance.com>
Sun, 20 Apr 2014 04:46:05 +0000 (00:46 -0400)
Fix by 'amathew', test by Marek Stepniowski.

Lib/test/test_minidom.py
Lib/xml/dom/expatbuilder.py
Misc/ACKS
Misc/NEWS

index a1516c242da5330dcc39b3fc58af8d796249e14f..5ab4bfe1a4f727b2e2349830adc0b0dbd66fd4b3 100644 (file)
@@ -1518,6 +1518,10 @@ class MinidomTest(unittest.TestCase):
         doc2 = parseString(doc.toxml())
         self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE)
 
+    def testExceptionOnSpacesInXMLNSValue(self):
+        with self.assertRaisesRegex(ValueError, 'Unsupported syntax'):
+            parseString('<element xmlns:abc="http:abc.com/de f g/hi/j k"><abc:foo /></element>')
+
     def testDocRemoveChild(self):
         doc = parse(tstfile)
         title_tag = doc.documentElement.getElementsByTagName("TITLE")[0]
index 81e2df70d7a41c67825b9825f861b77667211648..897614434067dbbb45a22f3893b42172f0a7f5a3 100644 (file)
@@ -121,10 +121,12 @@ def _parse_ns_name(builder, name):
         qname = "%s:%s" % (prefix, localname)
         qname = intern(qname, qname)
         localname = intern(localname, localname)
-    else:
+    elif len(parts) == 2:
         uri, localname = parts
         prefix = EMPTY_PREFIX
         qname = localname = intern(localname, localname)
+    else:
+        raise ValueError("Unsupported syntax: spaces in URIs not supported: %r" % name)
     return intern(uri, uri), localname, prefix, qname
 
 
index 65d1adbe05694c192c3fb9f8622f75a3e0dfea3b..4173917e7314d79419d128e656a74a630f9c20b7 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1255,6 +1255,7 @@ Joel Stanley
 Anthony Starks
 Oliver Steele
 Greg Stein
+Marek Stepniowski
 Baruch Sterin
 Chris Stern
 Alex Stewart
index 5edfb042a8dd415f6b29968cbe3bafec837fb713..804f1ae41ebcd65a9f49ddfa2e260fa7b08707ee 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -39,6 +39,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #12220: mindom now raises a custom ValueError indicating it doesn't
+  support spaces in URIs instead of letting a 'split' ValueError bubble up.
+
 - Issue #21239: patch.stopall() didn't work deterministically when the same
   name was patched more than once.