Repository navigation
Honor native XML encodings and declaration callbacks - #9845
youknowone merged 2 commits into
Conversation
Honor explicit encodings, detect BOM-less UTF-16 before starting the backend, and preserve raw declaration metadata without decoding document content outside the XML parser. Restore the three SAX encoding regression tests. Assisted-by: OpenAI Codex:GPT-6.1
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/xml dependencies:
dependent tests: (39 tests)
Legend:
|
Address Rust 1.100 Clippy diagnostics without changing encoding behavior. Assisted-by: OpenAI Codex:GPT-6.1
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 791fdbc439
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| xml::ParserConfig::new() | ||
| .override_encoding(unicode_input.then_some(xml::Encoding::Utf8)) | ||
| .ignore_invalid_encoding_declarations(unicode_input) | ||
| .override_encoding(encoding) |
There was a problem hiding this comment.
Preserve BOM detection when applying explicit encodings
For byte input with a UTF-16 BOM, the requested native encoding must not suppress BOM detection. CPython 3.14 accepts ParserCreate('UTF-8').Parse('<r/>'.encode('utf-16'), True), and the previous byte-input configuration left xml-rs's BOM detection enabled. Passing Some(Utf8) to override_encoding instead forces UTF-8 decoding, so this previously accepted document now fails on the BOM. Honor the BOM-derived encoding before applying the requested encoding; overriding an XML declaration is not equivalent to overriding byte-order detection.
Useful? React with 👍 / 👎.
Summary
ParserCreate(encoding=...)for the six native XML encodings instead of discarding it. Keep the firstParseinput mode when byte/string chunks are mixed.XmlDeclHandleronly after the backend validates the declaration. No declaration does not produce a synthetic callback, and omitted encoding remainsNone.The document is still decoded by the native XML backend. This does not add a general Python-codec-to-UTF-8 preprocessor: that would change Expat's codec lookup/callback order and byte positions. Unknown/custom encodings, DTD callbacks, namespace declaration fidelity and existing backend diagnostic differences remain outside this patch. The corresponding expected-failure markers remain.
Reference
Compared against CPython 3.15
Modules/pyexpat.c(ParserCreate,Parse,XML_SetEncoding, declaration callbacks) and its Expat encoding initialization. This is independent of #9838's character buffering work and based directly on current main.Validation
cargo check -p rustpython-stdlib --lib: passed.-m test test_pyexpat test_sax test_xml_etree test_xmlrpc test_pulldom: passed, 606 tests, 26 skipped._ctypes/_lzma/_sqlite3missing from the reference CPython build. The six failing RustPython snippets also fail on the unchanged baseline binary.must_use_candidatewarnings in unchangedsrc/lib.rsandsrc/main.rs. The latest-head CI is still in progress.chunks_exact_to_as_chunks,manual_is_multiple_of) were corrected in791fdbc43; no lint suppression was added. The WASM job had failed on these same diagnostics.No sanitizer, Windows or wasm execution has been performed locally yet.