[utils] fix_xml_ampersands: Fix numeric character references (#17842)

Authored by: doe1080
This commit is contained in:
doe1080
2026-12-01 06:19:39 +00:00
committed by GitHub
parent 0e4dc0b041
commit 38a11b23d7
2 changed files with 4 additions and 1 deletions
+3
View File
@@ -780,6 +780,9 @@ class TestUtil(unittest.TestCase):
'&'><"')
self.assertEqual(
fix_xml_ampersands('Ӓ᪼'), 'Ӓ᪼')
self.assertEqual(
fix_xml_ampersands('😀😀'), '😀😀')
self.assertEqual(fix_xml_ampersands('&#;&#x;'), '&#;&#x;')
self.assertEqual(fix_xml_ampersands('&#&#'), '&#&#')
def test_paged_list(self):
+1 -1
View File
@@ -1939,7 +1939,7 @@ def month_by_abbreviation(abbrev):
def fix_xml_ampersands(xml_str):
"""Replace all the '&' by '&' in XML"""
return re.sub(
r'&(?!amp;|lt;|gt;|apos;|quot;|#x[0-9a-fA-F]{,4};|#[0-9]{,4};)',
r'&(?!amp;|lt;|gt;|apos;|quot;|#x[0-9a-fA-F]+;|#[0-9]+;)',
'&',
xml_str)