Skip to content

Commit 2cae938

Browse files
authored
bpo-46811: Make test suite support Expat >=2.4.5 (pythonGH-31453)
Curly brackets were never allowed in namespace URIs according to RFC 3986, and so-called namespace-validating XML parsers have the right to reject them a invalid URIs. libexpat >=2.4.5 has become strcter in that regard due to related security issues; with ET.XML instantiating a namespace-aware parser under the hood, this test has no future in CPython. References: - https://datatracker.ietf.org/doc/html/rfc3968 - https://www.w3.org/TR/xml-names/ Also, test_minidom.py: Support Expat >=2.4.5
1 parent 2b86616 commit 2cae938

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

Lib/test/test_minidom.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
from test import support
77
import unittest
88

9+
import pyexpat
910
import xml.dom.minidom
1011

1112
from xml.dom.minidom import parse, Node, Document, parseString
1213
from xml.dom.minidom import getDOMImplementation
14+
from xml.parsers.expat import ExpatError
1315

1416

1517
tstfile = support.findfile("test.xml", subdir="xmltestdata")
@@ -1147,7 +1149,13 @@ def testEncodings(self):
11471149

11481150
# Verify that character decoding errors raise exceptions instead
11491151
# of crashing
1150-
self.assertRaises(UnicodeDecodeError, parseString,
1152+
if pyexpat.version_info >= (2, 4, 5):
1153+
self.assertRaises(ExpatError, parseString,
1154+
b'<fran\xe7ais></fran\xe7ais>')
1155+
self.assertRaises(ExpatError, parseString,
1156+
b'<franais>Comment \xe7a va ? Tr\xe8s bien ?</franais>')
1157+
else:
1158+
self.assertRaises(UnicodeDecodeError, parseString,
11511159
b'<fran\xe7ais>Comment \xe7a va ? Tr\xe8s bien ?</fran\xe7ais>')
11521160

11531161
doc.unlink()
@@ -1609,7 +1617,12 @@ def testEmptyXMLNSValue(self):
16091617
self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE)
16101618

16111619
def testExceptionOnSpacesInXMLNSValue(self):
1612-
with self.assertRaisesRegex(ValueError, 'Unsupported syntax'):
1620+
if pyexpat.version_info >= (2, 4, 5):
1621+
context = self.assertRaisesRegex(ExpatError, 'syntax error')
1622+
else:
1623+
context = self.assertRaisesRegex(ValueError, 'Unsupported syntax')
1624+
1625+
with context:
16131626
parseString('<element xmlns:abc="http:abc.com/de f g/hi/j k"><abc:foo /></element>')
16141627

16151628
def testDocRemoveChild(self):

Lib/test/test_xml_etree.py

-6
Original file line numberDiff line numberDiff line change
@@ -2192,12 +2192,6 @@ def test_issue6233(self):
21922192
b"<?xml version='1.0' encoding='ascii'?>\n"
21932193
b'<body>t&#227;g</body>')
21942194

2195-
def test_issue3151(self):
2196-
e = ET.XML('<prefix:localname xmlns:prefix="${stuff}"/>')
2197-
self.assertEqual(e.tag, '{${stuff}}localname')
2198-
t = ET.ElementTree(e)
2199-
self.assertEqual(ET.tostring(e), b'<ns0:localname xmlns:ns0="${stuff}" />')
2200-
22012195
def test_issue6565(self):
22022196
elem = ET.XML("<body><tag/></body>")
22032197
self.assertEqual(summarize_list(elem), ['tag'])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make test suite support Expat >=2.4.5

0 commit comments

Comments
 (0)