From e55da04e77ddebb1bba378b9b9e6538f0e664b30 Mon Sep 17 00:00:00 2001 From: Michael Karcher Date: Sat, 29 Nov 2008 10:51:20 +0100 Subject: [PATCH] msxml3: Avoid duplicate encoding. The libxml documentation suggests to either use xmlEncodedEntitiesReentrant or xmlEncodeSpecialChars, but if you apply both, you end up producing "&amp;". --- dlls/msxml3/node.c | 8 +++----- dlls/msxml3/tests/domdoc.c | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/dlls/msxml3/node.c b/dlls/msxml3/node.c index 19cee8f3f86..3d6f2f34000 100644 --- a/dlls/msxml3/node.c +++ b/dlls/msxml3/node.c @@ -920,7 +920,7 @@ static HRESULT WINAPI xmlnode_put_text( BSTR text) { xmlnode *This = impl_from_IXMLDOMNode( iface ); - xmlChar *str, *str2, *str3; + xmlChar *str, *str2; TRACE("%p\n", This); @@ -937,11 +937,9 @@ static HRESULT WINAPI xmlnode_put_text( /* Escape the string. */ str2 = xmlEncodeEntitiesReentrant(This->node->doc, str); HeapFree(GetProcessHeap(), 0, str); - str3 = xmlEncodeSpecialChars(This->node->doc, str2); - xmlFree(str2); - xmlNodeSetContent(This->node, str3); - xmlFree(str3); + xmlNodeSetContent(This->node, str2); + xmlFree(str2); return S_OK; } diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c index e27c5064fd8..4cff3cc454e 100644 --- a/dlls/msxml3/tests/domdoc.c +++ b/dlls/msxml3/tests/domdoc.c @@ -176,6 +176,8 @@ static WCHAR szElementXML[] = {'<','E','l','e','T','e','s','t','/','>',0 }; static WCHAR szElementXML2[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','/','>',0 }; static WCHAR szElementXML3[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>', 'T','e','s','t','i','n','g','N','o','d','e','<','/','E','l','e','T','e','s','t','>',0 }; +static WCHAR szElementXML4[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>', + '&','a','m','p',';','x',' ',0x2103,'<','/','E','l','e','T','e','s','t','>',0 }; static WCHAR szAttribute[] = {'A','t','t','r',0 }; static WCHAR szAttributeXML[] = {'A','t','t','r','=','"','"',0 }; @@ -190,6 +192,7 @@ static WCHAR szDocFragmentText[] = {'#','d','o','c','u','m','e','n','t','-','f', static WCHAR szEntityRef[] = {'e','n','t','i','t','y','r','e','f',0 }; static WCHAR szEntityRefXML[] = {'&','e','n','t','i','t','y','r','e','f',';',0 }; +static WCHAR szStrangeChars[] = {'&','x',' ',0x2103, 0}; #define expect_bstr_eq_and_free(bstr, expect) { \ BSTR bstrExp = alloc_str_from_narrow(expect); \ @@ -2893,6 +2896,22 @@ static void test_xmlTypes(void) ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n"); SysFreeString(str); + /* Test for reversible escaping */ + str = SysAllocString( szStrangeChars ); + hr = IXMLDOMElement_put_text(pElement, str); + ok(hr == S_OK, "ret %08x\n", hr ); + SysFreeString( str ); + + hr = IXMLDOMElement_get_xml(pElement, &str); + ok(hr == S_OK, "ret %08x\n", hr ); + ok( !lstrcmpW( str, szElementXML4 ), "incorrect element xml\n"); + SysFreeString(str); + + hr = IXMLDOMElement_get_text(pElement, &str); + ok(hr == S_OK, "ret %08x\n", hr ); + ok( !lstrcmpW( str, szStrangeChars ), "incorrect element text\n"); + SysFreeString(str); + IXMLDOMElement_Release(pElement); }