mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-24 13:33:01 +03:00
Fix encoding selection for xmlParseInNodeContext
* parser.c: use the encoding from the document to parse the chunk
This commit is contained in:
30
parser.c
30
parser.c
@@ -12884,14 +12884,8 @@ xmlParseInNodeContext(xmlNodePtr node, const char *data, int datalen,
|
|||||||
|
|
||||||
if (ctxt == NULL)
|
if (ctxt == NULL)
|
||||||
return(XML_ERR_NO_MEMORY);
|
return(XML_ERR_NO_MEMORY);
|
||||||
fake = xmlNewComment(NULL);
|
|
||||||
if (fake == NULL) {
|
|
||||||
xmlFreeParserCtxt(ctxt);
|
|
||||||
return(XML_ERR_NO_MEMORY);
|
|
||||||
}
|
|
||||||
xmlAddChild(node, fake);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Use input doc's dict if present, else assure XML_PARSE_NODICT is set.
|
* Use input doc's dict if present, else assure XML_PARSE_NODICT is set.
|
||||||
* We need a dictionary for xmlDetectSAX2, so if there's no doc dict
|
* We need a dictionary for xmlDetectSAX2, so if there's no doc dict
|
||||||
* we must wait until the last moment to free the original one.
|
* we must wait until the last moment to free the original one.
|
||||||
@@ -12903,10 +12897,32 @@ xmlParseInNodeContext(xmlNodePtr node, const char *data, int datalen,
|
|||||||
} else
|
} else
|
||||||
options |= XML_PARSE_NODICT;
|
options |= XML_PARSE_NODICT;
|
||||||
|
|
||||||
|
if (doc->encoding != NULL) {
|
||||||
|
xmlCharEncodingHandlerPtr hdlr;
|
||||||
|
|
||||||
|
if (ctxt->encoding != NULL)
|
||||||
|
xmlFree((xmlChar *) ctxt->encoding);
|
||||||
|
ctxt->encoding = xmlStrdup((const xmlChar *) doc->encoding);
|
||||||
|
|
||||||
|
hdlr = xmlFindCharEncodingHandler(doc->encoding);
|
||||||
|
if (hdlr != NULL) {
|
||||||
|
xmlSwitchToEncoding(ctxt, hdlr);
|
||||||
|
} else {
|
||||||
|
return(XML_ERR_UNSUPPORTED_ENCODING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
xmlCtxtUseOptionsInternal(ctxt, options, NULL);
|
xmlCtxtUseOptionsInternal(ctxt, options, NULL);
|
||||||
xmlDetectSAX2(ctxt);
|
xmlDetectSAX2(ctxt);
|
||||||
ctxt->myDoc = doc;
|
ctxt->myDoc = doc;
|
||||||
|
|
||||||
|
fake = xmlNewComment(NULL);
|
||||||
|
if (fake == NULL) {
|
||||||
|
xmlFreeParserCtxt(ctxt);
|
||||||
|
return(XML_ERR_NO_MEMORY);
|
||||||
|
}
|
||||||
|
xmlAddChild(node, fake);
|
||||||
|
|
||||||
if (node->type == XML_ELEMENT_NODE) {
|
if (node->type == XML_ELEMENT_NODE) {
|
||||||
nodePush(ctxt, node);
|
nodePush(ctxt, node);
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user