mirror of
https://gitlab.gnome.org/GNOME/libxml2
synced 2025-03-28 21:33:13 +00:00
html: Fix htmlCreatePushParserCtxt with encoding
Regression from commit ec7be506. Fixes #696.
This commit is contained in:
parent
387a952bdb
commit
0b5650067b
@ -5987,7 +5987,7 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data,
|
||||
|
||||
xmlInitParser();
|
||||
|
||||
buf = xmlAllocParserInputBuffer(enc);
|
||||
buf = xmlAllocParserInputBuffer(XML_CHAR_ENCODING_NONE);
|
||||
if (buf == NULL) return(NULL);
|
||||
|
||||
ctxt = htmlNewSAXParserCtxt(sax, user_data);
|
||||
@ -6018,6 +6018,9 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data,
|
||||
|
||||
inputPush(ctxt, inputStream);
|
||||
|
||||
if (enc != XML_CHAR_ENCODING_NONE)
|
||||
xmlSwitchEncoding(ctxt, enc);
|
||||
|
||||
if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
|
||||
(ctxt->input->buf != NULL)) {
|
||||
size_t pos = ctxt->input->cur - ctxt->input->base;
|
||||
|
34
testparser.c
34
testparser.c
@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/HTMLparser.h>
|
||||
|
||||
static int
|
||||
testStandaloneWithEncoding(void) {
|
||||
@ -86,6 +87,36 @@ testHugeEncodedChunk(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LIBXML_HTML_ENABLED) && defined(LIBXML_PUSH_ENABLED)
|
||||
static int
|
||||
testHtmlPushWithEncoding(void) {
|
||||
htmlParserCtxtPtr ctxt;
|
||||
htmlDocPtr doc;
|
||||
htmlNodePtr node;
|
||||
int err = 0;
|
||||
|
||||
ctxt = htmlCreatePushParserCtxt(NULL, NULL, NULL, 0, NULL,
|
||||
XML_CHAR_ENCODING_UTF8);
|
||||
htmlParseChunk(ctxt, "-\xC3\xA4-", 4, 1);
|
||||
|
||||
doc = ctxt->myDoc;
|
||||
if (!xmlStrEqual(doc->encoding, BAD_CAST "UTF-8")) {
|
||||
fprintf(stderr, "testHtmlPushWithEncoding failed\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
node = xmlDocGetRootElement(doc)->children->children->children;
|
||||
if (!xmlStrEqual(node->content, BAD_CAST "-\xC3\xA4-")) {
|
||||
fprintf(stderr, "testHtmlPushWithEncoding failed\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
xmlFreeDoc(doc);
|
||||
htmlFreeParserCtxt(ctxt);
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
main(void) {
|
||||
int err = 0;
|
||||
@ -95,6 +126,9 @@ main(void) {
|
||||
err |= testHugePush();
|
||||
err |= testHugeEncodedChunk();
|
||||
#endif
|
||||
#if defined(LIBXML_HTML_ENABLED) && defined(LIBXML_PUSH_ENABLED)
|
||||
err |= testHtmlPushWithEncoding();
|
||||
#endif
|
||||
|
||||
return err;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user