8000 bpo-46811: Make test suite support Expat >=2.4.5 (GH-31453) (GH-31471) · python/cpython@d4f5bb9 · GitHub
[go: up one dir, main page]

Skip to content

Commit d4f5bb9

Browse files
bpo-46811: Make test suite support Expat >=2.4.5 (GH-31453) (GH-31471)
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 (cherry picked from commit 2cae938) Co-authored-by: Sebastian Pipping <sebastian@pipping.org>
1 parent 5fdacac commit d4f5bb9

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

Lib/test/test_minidom.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
from test import support
66
import unittest
77

8+
import pyexpat
89
import xml.dom.minidom
910

1011
from xml.dom.minidom import parse, Node, Document, parseString
1112
from xml.dom.minidom import getDOMImplementation
13+
from xml.parsers.expat import ExpatError
1214

1315

1416
tstfile = support.findfile("test.xml", subdir="xmltestdata")
@@ -1146,7 +1148,13 @@ def testEncodings(self):
11461148

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

11521160
doc.unlink()
@@ -1592,7 +1600,12 @@ def testEmptyXMLNSValue(self):
15921600
self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE)
15931601

15941602
def testExceptionOnSpacesInXMLNSValue(self):
1595-
with self.assertRaisesRegex(ValueError, 'Unsupported syntax'):
1603+
if pyexpat.version_info >= (2, 4, 5):
1604+
context = self.assertRaisesRegex(ExpatError, 'syntax error')
1605+
else:
1606+
context = self.assertRaisesRegex(ValueError, 'Unsupported syntax')
1607+
1608+
with context:
15961609
parseString('<element xmlns:abc="http:abc.com/de f g/hi/j k"><abc:foo /></element>')
15971610

15981611
def testDocRemoveChild(self):

Lib/test/test_xml_etree.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,12 +1683,6 @@ def test_issue6233(self):
16831683
b"<?xml version='1.0' encoding='ascii'?>\n"
16841684
b'<body>t&#227;g</body>')
16851685

1686-
def test_issue3151(self):
1687-
e = ET.XML('<prefix:localname xmlns:prefix="${stuff}"/>')
1688-
self.assertEqual(e.tag, '{${stuff}}localname')
1689-
t = ET.ElementTree(e)
1690-
self.assertEqual(ET.tostring(e), b'<ns0:localname xmlns:ns0="${stuff}" />')
1691-
16921686
def test_issue6565(self):
16931687
elem = ET.XML("<body><tag/></body>")
16941688
self.assertEqual(summarize_list(elem), ['tag'])
Lines changed: 1 addition & 0 deletions
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)
0