From fd9bcfcfe812c0c4f13f9c081e8d029d3966b605 Mon Sep 17 00:00:00 2001 From: Adam Martinson Date: Wed, 20 Oct 2010 17:00:21 -0500 Subject: [PATCH] msxml3: Fix a regression bug in domdoc_loadXML(). Caused by commit 776a8662f088e75e88284cc0fc8e72d768771a6f. Fixes parse failures for BSTR's where encoding is explicitly UTF-16. --- dlls/msxml3/domdoc.c | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/dlls/msxml3/domdoc.c b/dlls/msxml3/domdoc.c index c4011002f95..76692206c0d 100644 --- a/dlls/msxml3/domdoc.c +++ b/dlls/msxml3/domdoc.c @@ -51,6 +51,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(msxml); #include #include #include +#include /* not defined in older versions */ #define XML_SAVE_FORMAT 1 @@ -321,9 +322,10 @@ static void sax_characters(void *ctx, const xmlChar *ch, int len) xmlSAX2Characters(ctx, ch, len); } -static xmlDocPtr doparse(domdoc* This, char *ptr, int len) +static xmlDocPtr doparse(domdoc* This, char *ptr, int len, xmlChar const* encoding) { - xmlDocPtr doc; + xmlDocPtr doc = NULL; + xmlParserCtxtPtr pctx; static xmlSAXHandler sax_handler = { xmlSAX2InternalSubset, /* internalSubset */ xmlSAX2IsStandalone, /* isStandalone */ @@ -358,8 +360,33 @@ static xmlDocPtr doparse(domdoc* This, char *ptr, int len) xmlSAX2EndElementNs, /* endElementNs */ NULL /* TODO: serror */ }; + xmlInitParser(); - doc = xmlSAXParseMemoryWithData(&sax_handler, ptr, len, 0, This); + pctx = xmlCreateMemoryParserCtxt(ptr, len); + if (!pctx) + { + ERR("Failed to create parser context\n"); + return NULL; + } + + if (pctx->sax) xmlFree(pctx->sax); + pctx->sax = &sax_handler; + pctx->_private = This; + pctx->recovery = 0; + pctx->encoding = xmlStrdup(encoding); + xmlParseDocument(pctx); + + if (pctx->wellFormed) + { + doc = pctx->myDoc; + } + else + { + xmlFreeDoc(pctx->myDoc); + pctx->myDoc = NULL; + } + pctx->sax = NULL; + xmlFreeParserCtxt(pctx); /* TODO: put this in one of the SAX callbacks */ /* create first child as a */ @@ -597,7 +624,7 @@ static HRESULT WINAPI domdoc_IPersistStreamInit_Load( len = GlobalSize(hglobal); ptr = GlobalLock(hglobal); if (len != 0) - xmldoc = doparse(This, ptr, len); + xmldoc = doparse(This, ptr, len, NULL); GlobalUnlock(hglobal); if (!xmldoc) @@ -1789,7 +1816,7 @@ static HRESULT domdoc_onDataAvailable(void *obj, char *ptr, DWORD len) domdoc *This = obj; xmlDocPtr xmldoc; - xmldoc = doparse(This, ptr, len); + xmldoc = doparse(This, ptr, len, NULL); if(xmldoc) { xmldoc->_private = create_priv(); return attach_xmldoc(This, xmldoc); @@ -2017,6 +2044,7 @@ static HRESULT WINAPI domdoc_loadXML( VARIANT_BOOL* isSuccessful ) { domdoc *This = impl_from_IXMLDOMDocument3( iface ); + static const xmlChar encoding[] = "UTF-8"; xmlDocPtr xmldoc = NULL; HRESULT hr = S_FALSE, hr2; char *str; @@ -2032,10 +2060,13 @@ static HRESULT WINAPI domdoc_loadXML( if ( bstrXML && bstr_to_utf8( bstrXML, &str, &len ) ) { - xmldoc = doparse(This, str, len); + xmldoc = doparse(This, str, len, encoding); heap_free( str ); if ( !xmldoc ) + { This->error = E_FAIL; + TRACE("failed to parse document\n"); + } else { hr = This->error = S_OK; -- 2.11.4.GIT