From ae7cb41c1f0021362bd58d8e6923e7c50963ea90 Mon Sep 17 00:00:00 2001 From: FILICIAK Piotr Date: Tue, 4 Aug 2026 21:55:18 +0200 Subject: [PATCH] Fix encoding with libxml2 >= 2.12 push parser --- sope-xml/libxmlSAXDriver/libxmlHTMLSAXDriver.m | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sope-xml/libxmlSAXDriver/libxmlHTMLSAXDriver.m b/sope-xml/libxmlSAXDriver/libxmlHTMLSAXDriver.m index ca62bc931..8bf8b3747 100644 --- a/sope-xml/libxmlSAXDriver/libxmlHTMLSAXDriver.m +++ b/sope-xml/libxmlSAXDriver/libxmlHTMLSAXDriver.m @@ -29,6 +29,7 @@ #include #include +#include @interface NSObject(contentHandlerExtensions) @@ -248,6 +249,15 @@ - (void)setupParserWithDocumentPath:(NSString *)_path { 0 /* chunklen */, [_path cString] /* filename */, charEncoding /* encoding */); + + // The enc parameter of htmlCreatePushParserCtxt is deprecated and ignored + // in libxml2 >= 2.12. Use xmlSwitchEncoding() to explicitly set the + // encoding on the parser context. This is backward-compatible with older + // libxml2 versions where it is a harmless no-op. + if (self->ctxt && charEncoding != XML_CHAR_ENCODING_NONE) { + xmlSwitchEncoding((xmlParserCtxtPtr)self->ctxt, charEncoding); + } + self->doc = NULL; } - (void)tearDownParser {