Adam Martinson : msxml3/domdoc: Properly handle character encoding in doparse().

Alexandre Julliard julliard at winehq.org
Fri May 20 12:44:34 CDT 2011


Module: wine
Branch: master
Commit: 17f72b8b675abda5656a680ecc56cb3c3128d879
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=17f72b8b675abda5656a680ecc56cb3c3128d879

Author: Adam Martinson <amartinson at codeweavers.com>
Date:   Fri May 20 10:05:05 2011 -0500

msxml3/domdoc: Properly handle character encoding in doparse().

---

 dlls/msxml3/domdoc.c |   34 +++++++++-------------------------
 1 files changed, 9 insertions(+), 25 deletions(-)

diff --git a/dlls/msxml3/domdoc.c b/dlls/msxml3/domdoc.c
index 84b7283..07391b4 100644
--- a/dlls/msxml3/domdoc.c
+++ b/dlls/msxml3/domdoc.c
@@ -455,7 +455,7 @@ static void sax_serror(void* ctx, xmlErrorPtr err)
     LIBXML2_CALLBACK_SERROR(doparse, err);
 }
 
-static xmlDocPtr doparse(domdoc* This, char *ptr, int len, xmlChar const* encoding)
+static xmlDocPtr doparse(domdoc* This, char const* ptr, int len, xmlCharEncoding encoding)
 {
     xmlDocPtr doc = NULL;
     xmlParserCtxtPtr pctx;
@@ -506,7 +506,10 @@ static xmlDocPtr doparse(domdoc* This, char *ptr, int len, xmlChar const* encodi
     pctx->sax = &sax_handler;
     pctx->_private = This;
     pctx->recovery = 0;
-    pctx->encoding = xmlStrdup(encoding);
+
+    if (encoding != XML_CHAR_ENCODING_NONE)
+        xmlSwitchEncoding(pctx, encoding);
+
     xmlParseDocument(pctx);
 
     if (pctx->wellFormed)
@@ -763,7 +766,7 @@ static HRESULT WINAPI domdoc_IPersistStreamInit_Load(
     len = GlobalSize(hglobal);
     ptr = GlobalLock(hglobal);
     if (len != 0)
-        xmldoc = doparse(This, ptr, len, NULL);
+        xmldoc = doparse(This, ptr, len, XML_CHAR_ENCODING_NONE);
     GlobalUnlock(hglobal);
 
     if (!xmldoc)
@@ -2071,7 +2074,7 @@ static HRESULT domdoc_onDataAvailable(void *obj, char *ptr, DWORD len)
     domdoc *This = obj;
     xmlDocPtr xmldoc;
 
-    xmldoc = doparse(This, ptr, len, NULL);
+    xmldoc = doparse(This, ptr, len, XML_CHAR_ENCODING_NONE);
     if(xmldoc) {
         xmldoc->_private = create_priv();
         return attach_xmldoc(This, xmldoc);
@@ -2279,21 +2282,6 @@ static HRESULT WINAPI domdoc_abort(
 }
 
 
-static BOOL bstr_to_utf8( BSTR bstr, char **pstr, int *plen )
-{
-    UINT len;
-    LPSTR str;
-
-    len = WideCharToMultiByte( CP_UTF8, 0, bstr, -1, NULL, 0, NULL, NULL );
-    str = heap_alloc( len );
-    if ( !str )
-        return FALSE;
-    WideCharToMultiByte( CP_UTF8, 0, bstr, -1, str, len, NULL, NULL );
-    *plen = len;
-    *pstr = str;
-    return TRUE;
-}
-
 /* don't rely on data to be in BSTR format, treat it as WCHAR string */
 static HRESULT WINAPI domdoc_loadXML(
     IXMLDOMDocument3 *iface,
@@ -2301,11 +2289,8 @@ 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;
-    int len;
 
     TRACE("(%p)->(%s %p)\n", This, debugstr_w( bstrXML ), isSuccessful );
 
@@ -2315,10 +2300,9 @@ static HRESULT WINAPI domdoc_loadXML(
     {
         *isSuccessful = VARIANT_FALSE;
 
-        if ( bstrXML && bstr_to_utf8( bstrXML, &str, &len ) )
+        if ( bstrXML )
         {
-            xmldoc = doparse(This, str, len, encoding);
-            heap_free( str );
+            xmldoc = doparse(This, (LPCSTR)bstrXML, lstrlenW(bstrXML) * sizeof(*bstrXML), XML_CHAR_ENCODING_UTF16LE);
             if ( !xmldoc )
             {
                 This->error = E_FAIL;




More information about the wine-cvs mailing list