Skip to content

Commit 7031275

Browse files
authored
gh-93018: Fix for the compatibility problems with expat (gh-93900)
1 parent 889b0b9 commit 7031275

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

Lib/test/test_minidom.py

+9-15
Original file line numberDiff line numberDiff line change
@@ -1163,14 +1163,10 @@ def testEncodings(self):
11631163

11641164
# Verify that character decoding errors raise exceptions instead
11651165
# of crashing
1166-
if pyexpat.version_info >= (2, 4, 5):
1167-
self.assertRaises(ExpatError, parseString,
1168-
b'<fran\xe7ais></fran\xe7ais>')
1169-
self.assertRaises(ExpatError, parseString,
1170-
b'<franais>Comment \xe7a va ? Tr\xe8s bien ?</franais>')
1171-
else:
1172-
self.assertRaises(UnicodeDecodeError, parseString,
1173-
b'<fran\xe7ais>Comment \xe7a va ? Tr\xe8s bien ?</fran\xe7ais>')
1166+
with self.assertRaises((UnicodeDecodeError, ExpatError)):
1167+
parseString(
1168+
b'<fran\xe7ais>Comment \xe7a va ? Tr\xe8s bien ?</fran\xe7ais>'
1169+
)
11741170

11751171
doc.unlink()
11761172

@@ -1631,13 +1627,11 @@ def testEmptyXMLNSValue(self):
16311627
self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE)
16321628

16331629
def testExceptionOnSpacesInXMLNSValue(self):
1634-
if pyexpat.version_info >= (2, 4, 5):
1635-
context = self.assertRaisesRegex(ExpatError, 'syntax error')
1636-
else:
1637-
context = self.assertRaisesRegex(ValueError, 'Unsupported syntax')
1638-
1639-
with context:
1640-
parseString('<element xmlns:abc="http:abc.com/de f g/hi/j k"><abc:foo /></element>')
1630+
with self.assertRaises((ValueError, ExpatError)):
1631+
parseString(
1632+
'<element xmlns:abc="http:abc.com/de f g/hi/j k">' +
1633+
'<abc:foo /></element>'
1634+
)
16411635

16421636
def testDocRemoveChild(self):
16431637
doc = parse(tstfile)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make two tests forgiving towards host system libexpat with backported security fixes applied.

0 commit comments

Comments
 (0)