gh-146169: correctly handle re-entrant parsing calls in Expat handlers#146566
gh-146169: correctly handle re-entrant parsing calls in Expat handlers#146566picnixz wants to merge 2 commits intopython:mainfrom
Conversation
Misc/NEWS.d/next/Library/2026-03-28-10-27-46.gh-issue-146169.RBF1xp.rst
Outdated
Show resolved
Hide resolved
|
@hartwork I'd like your feedback here to know whether there are other places that I need to consider. I will work on the encoding issue described in the GH issue afterwards unless they are interconnected. TiA! |
|
|
||
| def ExternalEntityRefHandler(*args): | ||
| subparser.Parse(payload_extstr, True) | ||
| return 1 # return an integer to indicate that parsing continues |
There was a problem hiding this comment.
This comment seems to nee fixing:
| return 1 # return an integer to indicate that parsing continues | |
| return 1 # return a non-zero integer to indicate that parsing continues |
| payload = f"""\ | ||
| <?xml version="1.0" standalone="no"?> | ||
| <!DOCTYPE quotations SYSTEM "quotations.dtd" [{payload_extstr}]> | ||
| <root>&ext;</root> | ||
| """.encode(encoding) |
There was a problem hiding this comment.
Just an idea: Use of dedent could help with readability here:
| payload = f"""\ | |
| <?xml version="1.0" standalone="no"?> | |
| <!DOCTYPE quotations SYSTEM "quotations.dtd" [{payload_extstr}]> | |
| <root>&ext;</root> | |
| """.encode(encoding) | |
| payload = dedent(f"""\ | |
| <?xml version="1.0" standalone="no"?> | |
| <!DOCTYPE quotations SYSTEM "quotations.dtd" [{payload_extstr}]> | |
| <root>&ext;</root> | |
| """).encode(encoding) |
| if (self->in_callback) { | ||
| PyErr_SetString(PyExc_RuntimeError, | ||
| "cannot call Parse() from within a handler"); | ||
| return NULL; | ||
| } | ||
|
|
There was a problem hiding this comment.
Does ParseFile or function pyexpat_xmlparser_ParseFile_impl need something similar?
PS: Also — other than pyexpat_xmlparser_Parse_impl — it does not seem to call XML_SetEncoding. That asymmetry seems unintended (but maybe I am missing something). Maybe such a call is missing.
There was a problem hiding this comment.
Oh maybe, I will check. As for XML_SetEncoding, I don't know. I'll have a look at it tomorrow!
Uh oh!
There was an error while loading. Please reload this page.