Skip to content

Commit b5cbc8c

Browse files
committed
Route XML declaration callbacks through buffered error cleanup
Preserve callback abort semantics when integrating the native encoding changes from main. Assisted-by: OpenAI Codex
1 parent 8459df5 commit b5cbc8c

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎crates/stdlib/src/pyexpat.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,7 @@ mod _pyexpat {
16701670
.store(standalone == Some(true), Ordering::Relaxed);
16711671
let declaration = self.declaration.write().take();
16721672
if let Some(declaration) = declaration {
1673-
invoke_handler(
1673+
self.invoke_buffered_handler(
16741674
vm,
16751675
&self.xml_decl,
16761676
(

‎extra_tests/snippets/stdlib_pyexpat.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,22 @@ def fail_character_callback(text):
327327
raise AssertionError("non-integer external handler result accepted")
328328
assert parser.ExternalEntityRefHandler is invalid_result
329329
assert parser.Parse(b"", True) == 1
330+
331+
# Declaration callbacks participate in the same non-resumable error cleanup.
332+
parser = expat.ParserCreate()
333+
334+
335+
def fail_declaration(*args):
336+
raise ValueError("declaration failure")
337+
338+
339+
parser.XmlDeclHandler = fail_declaration
340+
parser.StartElementHandler = lambda *args: None
341+
try:
342+
parser.Parse(b'<?xml version="1.0"?><r/>', True)
343+
except ValueError as exc:
344+
assert str(exc) == "declaration failure"
345+
else:
346+
raise AssertionError("declaration exception swallowed")
347+
assert parser.XmlDeclHandler is None
348+
assert parser.StartElementHandler is None

0 commit comments

Comments
 (0)