[libxml2] Fix encoding selection for xmlParseInNodeContext
- From: Daniel Veillard <veillard src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libxml2] Fix encoding selection for xmlParseInNodeContext
- Date: Thu, 4 Feb 2010 17:49:39 +0000 (UTC)
commit 47cd14e850ebfeff9907ec5fd36a68f628863e1f
Author: Daniel Veillard <veillard redhat com>
Date: Thu Feb 4 18:49:01 2010 +0100
Fix encoding selection for xmlParseInNodeContext
* parser.c: use the encoding from the document to parse the chunk
parser.c | 30 +++++++++++++++++++++++-------
1 files changed, 23 insertions(+), 7 deletions(-)
---
diff --git a/parser.c b/parser.c
index 4d85966..0834d13 100644
--- a/parser.c
+++ b/parser.c
@@ -12884,14 +12884,8 @@ xmlParseInNodeContext(xmlNodePtr node, const char *data, int datalen,
if (ctxt == NULL)
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.
* 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.
@@ -12903,10 +12897,32 @@ xmlParseInNodeContext(xmlNodePtr node, const char *data, int datalen,
} else
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);
xmlDetectSAX2(ctxt);
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) {
nodePush(ctxt, node);
/*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]