Commit 8f976c5d authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

msxml3: Encode special characters while setting attribute content.

parent 9dedc4a7
......@@ -207,7 +207,7 @@ static HRESULT WINAPI domattr_put_nodeValue(
TRACE("(%p)->(v%d)\n", This, V_VT(&value));
return node_put_value(&This->node, &value);
return node_put_value_escaped(&This->node, &value);
}
static HRESULT WINAPI domattr_get_nodeType(
......
......@@ -184,6 +184,7 @@ extern HRESULT node_get_nodeName(xmlnode*,BSTR*);
extern HRESULT node_get_content(xmlnode*,VARIANT*);
extern HRESULT node_set_content(xmlnode*,LPCWSTR);
extern HRESULT node_put_value(xmlnode*,VARIANT*);
extern HRESULT node_put_value_escaped(xmlnode*,VARIANT*);
extern HRESULT node_get_parent(xmlnode*,IXMLDOMNode**);
extern HRESULT node_get_child_nodes(xmlnode*,IXMLDOMNodeList**);
extern HRESULT node_get_first_child(xmlnode*,IXMLDOMNode**);
......
......@@ -151,6 +151,29 @@ HRESULT node_set_content(xmlnode *This, LPCWSTR value)
return S_OK;
}
static HRESULT node_set_content_escaped(xmlnode *This, LPCWSTR value)
{
xmlChar *str, *escaped;
str = xmlChar_from_wchar(value);
if(!str)
return E_OUTOFMEMORY;
escaped = xmlEncodeSpecialChars(NULL, str);
if(!escaped)
{
heap_free(str);
return E_OUTOFMEMORY;
}
xmlNodeSetContent(This->node, escaped);
heap_free(str);
xmlFree(escaped);
return S_OK;
}
HRESULT node_put_value(xmlnode *This, VARIANT *value)
{
VARIANT string_value;
......@@ -169,6 +192,24 @@ HRESULT node_put_value(xmlnode *This, VARIANT *value)
return S_OK;
}
HRESULT node_put_value_escaped(xmlnode *This, VARIANT *value)
{
VARIANT string_value;
HRESULT hr;
VariantInit(&string_value);
hr = VariantChangeType(&string_value, value, 0, VT_BSTR);
if(FAILED(hr)) {
WARN("Couldn't convert to VT_BSTR\n");
return hr;
}
hr = node_set_content_escaped(This, V_BSTR(&string_value));
VariantClear(&string_value);
return S_OK;
}
static HRESULT get_node(
xmlnode *This,
const char *name,
......
......@@ -6056,8 +6056,11 @@ static void test_TransformWithLoadingLocalFile(void)
static void test_put_nodeValue(void)
{
static const WCHAR jeevesW[] = {'J','e','e','v','e','s',' ','&',' ','W','o','o','s','t','e','r',0};
IXMLDOMDocument *doc;
IXMLDOMText *text;
IXMLDOMEntityReference *entityref;
IXMLDOMAttribute *attr;
IXMLDOMNode *node;
HRESULT hr;
VARIANT data, type;
......@@ -6115,6 +6118,28 @@ static void test_put_nodeValue(void)
IXMLDOMNode_Release(node);
IXMLDOMEntityReference_Release(entityref);
/* supported types */
hr = IXMLDOMDocument_createTextNode(doc, _bstr_(""), &text);
ok(hr == S_OK, "ret %08x\n", hr );
V_VT(&data) = VT_BSTR;
V_BSTR(&data) = _bstr_("Jeeves & Wooster");
hr = IXMLDOMText_put_nodeValue(text, data);
ok(hr == S_OK, "ret %08x\n", hr );
IXMLDOMText_Release(text);
hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
ok(hr == S_OK, "ret %08x\n", hr );
V_VT(&data) = VT_BSTR;
V_BSTR(&data) = _bstr_("Jeeves & Wooster");
hr = IXMLDOMAttribute_put_nodeValue(attr, data);
ok(hr == S_OK, "ret %08x\n", hr );
hr = IXMLDOMAttribute_get_nodeValue(attr, &data);
ok(hr == S_OK, "ret %08x\n", hr );
ok(memcmp(V_BSTR(&data), jeevesW, sizeof(jeevesW)) == 0, "got %s\n",
wine_dbgstr_w(V_BSTR(&data)));
VariantClear(&data);
IXMLDOMAttribute_Release(attr);
free_bstrs();
IXMLDOMDocument_Release(doc);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment