]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-154738: Propagate reparse-deferral setting to pyexpat subparsers (GH-154739)
authortonghuaroot (童话) <tonghuaroot@gmail.com>
Fri, 31 Jul 2026 10:58:59 +0000 (18:58 +0800)
committerGitHub <noreply@github.com>
Fri, 31 Jul 2026 10:58:59 +0000 (12:58 +0200)
Lib/test/test_pyexpat.py
Misc/NEWS.d/next/Library/2026-07-26-00-00-00.gh-issue-154738.Rd5Pxe.rst [new file with mode: 0644]
Modules/pyexpat.c

index a2ef67baadd4afbc5a832007124be2c55a919dd5..54dfa95ce8bff1757556bb9fd483a56aeb625307 100644 (file)
@@ -1045,6 +1045,13 @@ class ParentParserLifetimeTest(unittest.TestCase):
         del parser
         del subparser
 
+    def test_subparser_inherits_reparse_deferral(self):
+        for enabled in (True, False):
+            parser = expat.ParserCreate()
+            parser.SetReparseDeferralEnabled(enabled)
+            subparser = parser.ExternalEntityParserCreate(None)
+            self.assertEqual(subparser.GetReparseDeferralEnabled(), enabled)
+
 
 class ExternalEntityParserCreateErrorTest(unittest.TestCase):
     """ExternalEntityParserCreate error paths should not crash or leak
diff --git a/Misc/NEWS.d/next/Library/2026-07-26-00-00-00.gh-issue-154738.Rd5Pxe.rst b/Misc/NEWS.d/next/Library/2026-07-26-00-00-00.gh-issue-154738.Rd5Pxe.rst
new file mode 100644 (file)
index 0000000..1a6e1a3
--- /dev/null
@@ -0,0 +1,3 @@
+Fix :meth:`!ExternalEntityParserCreate` not propagating the reparse-deferral
+setting to the subparser, which left :meth:`!GetReparseDeferralEnabled`
+returning an uninitialized value.  Patch by tonghuaroot.
index f9e7e057f7e0f7b39d775c9f9238fe2144f9a5e8..397a441f574fe45cd5a8487dbc8345964c68c432 100644 (file)
@@ -1118,6 +1118,7 @@ pyexpat_xmlparser_ExternalEntityParserCreate_impl(xmlparseobject *self,
     new_parser->specified_attributes = self->specified_attributes;
     new_parser->in_callback = 0;
     new_parser->ns_prefixes = self->ns_prefixes;
+    new_parser->reparse_deferral_enabled = self->reparse_deferral_enabled;
     new_parser->itself = XML_ExternalEntityParserCreate(self->itself, context,
                                                         encoding);
     // The new subparser will make use of the parent XML_Parser inside of Expat.