msxml3: Fix a regression bug in domdoc_loadXML().

Caused by commit 776a8662f0. Fixes parse
failures for BSTR's where encoding is explicitly UTF-16.
This commit is contained in:
Adam Martinson 2010-10-20 17:00:21 -05:00 committed by Alexandre Julliard
parent 0abee56788
commit fd9bcfcfe8
1 changed files with 37 additions and 6 deletions

View File

@ -51,6 +51,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(msxml);
#include <libxml/xpathInternals.h> #include <libxml/xpathInternals.h>
#include <libxml/xmlsave.h> #include <libxml/xmlsave.h>
#include <libxml/SAX2.h> #include <libxml/SAX2.h>
#include <libxml/parserInternals.h>
/* not defined in older versions */ /* not defined in older versions */
#define XML_SAVE_FORMAT 1 #define XML_SAVE_FORMAT 1
@ -321,9 +322,10 @@ static void sax_characters(void *ctx, const xmlChar *ch, int len)
xmlSAX2Characters(ctx, ch, 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 = { static xmlSAXHandler sax_handler = {
xmlSAX2InternalSubset, /* internalSubset */ xmlSAX2InternalSubset, /* internalSubset */
xmlSAX2IsStandalone, /* isStandalone */ xmlSAX2IsStandalone, /* isStandalone */
@ -358,8 +360,33 @@ static xmlDocPtr doparse(domdoc* This, char *ptr, int len)
xmlSAX2EndElementNs, /* endElementNs */ xmlSAX2EndElementNs, /* endElementNs */
NULL /* TODO: serror */ 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 */ /* TODO: put this in one of the SAX callbacks */
/* create first child as a <?xml...?> */ /* create first child as a <?xml...?> */
@ -597,7 +624,7 @@ static HRESULT WINAPI domdoc_IPersistStreamInit_Load(
len = GlobalSize(hglobal); len = GlobalSize(hglobal);
ptr = GlobalLock(hglobal); ptr = GlobalLock(hglobal);
if (len != 0) if (len != 0)
xmldoc = doparse(This, ptr, len); xmldoc = doparse(This, ptr, len, NULL);
GlobalUnlock(hglobal); GlobalUnlock(hglobal);
if (!xmldoc) if (!xmldoc)
@ -1789,7 +1816,7 @@ static HRESULT domdoc_onDataAvailable(void *obj, char *ptr, DWORD len)
domdoc *This = obj; domdoc *This = obj;
xmlDocPtr xmldoc; xmlDocPtr xmldoc;
xmldoc = doparse(This, ptr, len); xmldoc = doparse(This, ptr, len, NULL);
if(xmldoc) { if(xmldoc) {
xmldoc->_private = create_priv(); xmldoc->_private = create_priv();
return attach_xmldoc(This, xmldoc); return attach_xmldoc(This, xmldoc);
@ -2017,6 +2044,7 @@ static HRESULT WINAPI domdoc_loadXML(
VARIANT_BOOL* isSuccessful ) VARIANT_BOOL* isSuccessful )
{ {
domdoc *This = impl_from_IXMLDOMDocument3( iface ); domdoc *This = impl_from_IXMLDOMDocument3( iface );
static const xmlChar encoding[] = "UTF-8";
xmlDocPtr xmldoc = NULL; xmlDocPtr xmldoc = NULL;
HRESULT hr = S_FALSE, hr2; HRESULT hr = S_FALSE, hr2;
char *str; char *str;
@ -2032,10 +2060,13 @@ static HRESULT WINAPI domdoc_loadXML(
if ( bstrXML && bstr_to_utf8( bstrXML, &str, &len ) ) if ( bstrXML && bstr_to_utf8( bstrXML, &str, &len ) )
{ {
xmldoc = doparse(This, str, len); xmldoc = doparse(This, str, len, encoding);
heap_free( str ); heap_free( str );
if ( !xmldoc ) if ( !xmldoc )
{
This->error = E_FAIL; This->error = E_FAIL;
TRACE("failed to parse document\n");
}
else else
{ {
hr = This->error = S_OK; hr = This->error = S_OK;