From 38a11b23d70dd6fdf20a25f358e2fa89d0fc601e Mon Sep 17 00:00:00 2001 From: doe1080 <98906116+doe1080@users.noreply.github.com> Date: Tue, 1 Dec 2026 15:19:39 +0900 Subject: [PATCH] [utils] `fix_xml_ampersands`: Fix numeric character references (#17842) Authored by: doe1080 --- test/test_utils.py | 3 +++ yt_dlp/utils/_utils.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/test/test_utils.py b/test/test_utils.py index 274eded088..26baa2737b 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -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): diff --git a/yt_dlp/utils/_utils.py b/yt_dlp/utils/_utils.py index 2eb38f6347..93ae84a070 100644 --- a/yt_dlp/utils/_utils.py +++ b/yt_dlp/utils/_utils.py @@ -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)