Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9077d24

Browse files
committed
#12220: improve minidom error when URI contains spaces.
Fix by 'amathew', test by Marek Stepniowski.
1 parent 09ae544 commit 9077d24

4 files changed

Lines changed: 11 additions & 1 deletion

File tree

Lib/test/test_minidom.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,10 @@ def testEmptyXMLNSValue(self):
15181518
doc2 = parseString(doc.toxml())
15191519
self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE)
15201520

1521+
def testExceptionOnSpacesInXMLNSValue(self):
1522+
with self.assertRaisesRegex(ValueError, 'Unsupported syntax'):
1523+
parseString('<element xmlns:abc="http:abc.com/de f g/hi/j k"><abc:foo /></element>')
1524+
15211525
def testDocRemoveChild(self):
15221526
doc = parse(tstfile)
15231527
title_tag = doc.documentElement.getElementsByTagName("TITLE")[0]

Lib/xml/dom/expatbuilder.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,12 @@ def _parse_ns_name(builder, name):
121121
qname = "%s:%s" % (prefix, localname)
122122
qname = intern(qname, qname)
123123
localname = intern(localname, localname)
124-
else:
124+
elif len(parts) == 2:
125125
uri, localname = parts
126126
prefix = EMPTY_PREFIX
127127
qname = localname = intern(localname, localname)
128+
else:
129+
raise ValueError("Unsupported syntax: spaces in URIs not supported: %r" % name)
128130
return intern(uri, uri), localname, prefix, qname
129131

130132

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,7 @@ Joel Stanley
12551255
Anthony Starks
12561256
Oliver Steele
12571257
Greg Stein
1258+
Marek Stepniowski
12581259
Baruch Sterin
12591260
Chris Stern
12601261
Alex Stewart

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ Core and Builtins
3939
Library
4040
-------
4141

42+
- Issue #12220: mindom now raises a custom ValueError indicating it doesn't
43+
support spaces in URIs instead of letting a 'split' ValueError bubble up.
44+
4245
- Issue #21239: patch.stopall() didn't work deterministically when the same
4346
name was patched more than once.
4447

0 commit comments

Comments
 (0)