msxml3: Use element name length passed to content handler.

This commit is contained in:
Nikolay Sivov 2011-08-27 17:35:13 +04:00 committed by Alexandre Julliard
parent 9ae103f7f7
commit 2a6abc248d
2 changed files with 31 additions and 13 deletions

View File

@ -155,16 +155,16 @@ static void close_element_starttag(const mxwriter *This)
xmlOutputBufferWriteString(This->buffer, ">"); xmlOutputBufferWriteString(This->buffer, ">");
} }
static void set_element_name(mxwriter *This, const WCHAR *name) static void set_element_name(mxwriter *This, const WCHAR *name, int len)
{ {
SysFreeString(This->element); SysFreeString(This->element);
This->element = SysAllocString(name); This->element = name ? SysAllocStringLen(name, len) : NULL;
} }
static inline HRESULT flush_output_buffer(mxwriter *This) static inline HRESULT flush_output_buffer(mxwriter *This)
{ {
close_element_starttag(This); close_element_starttag(This);
set_element_name(This, NULL); set_element_name(This, NULL, 0);
xmlOutputBufferFlush(This->buffer); xmlOutputBufferFlush(This->buffer);
return write_data_to_stream(This); return write_data_to_stream(This);
} }
@ -763,10 +763,11 @@ static HRESULT WINAPI mxwriter_saxcontent_startElement(
return E_INVALIDARG; return E_INVALIDARG;
close_element_starttag(This); close_element_starttag(This);
set_element_name(This, QName ? QName : emptyW); set_element_name(This, QName ? QName : emptyW,
QName ? nQName : 0);
xmlOutputBufferWriteString(This->buffer, "<"); xmlOutputBufferWriteString(This->buffer, "<");
s = xmlchar_from_wchar(QName); s = xmlchar_from_wcharn(QName, nQName);
xmlOutputBufferWriteString(This->buffer, (char*)s); xmlOutputBufferWriteString(This->buffer, (char*)s);
heap_free(s); heap_free(s);
@ -843,7 +844,7 @@ static HRESULT WINAPI mxwriter_saxcontent_endElement(
} }
heap_free(s); heap_free(s);
set_element_name(This, NULL); set_element_name(This, NULL, 0);
return S_OK; return S_OK;
} }
@ -860,7 +861,7 @@ static HRESULT WINAPI mxwriter_saxcontent_characters(
if (!chars) return E_INVALIDARG; if (!chars) return E_INVALIDARG;
close_element_starttag(This); close_element_starttag(This);
set_element_name(This, NULL); set_element_name(This, NULL, 0);
if (nchars) if (nchars)
{ {

View File

@ -1720,27 +1720,44 @@ static void test_mxwriter_startendelement(void)
VariantClear(&dest); VariantClear(&dest);
hr = ISAXContentHandler_endElement(content, NULL, 0, NULL, 0, _bstr_("a:b"), 3); hr = ISAXContentHandler_endElement(content, NULL, 0, NULL, 0, _bstr_("a:b"), 3);
ok(hr == E_INVALIDARG, "got %08x\n", hr); EXPECT_HR(hr, E_INVALIDARG);
hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, _bstr_("a:b"), 3); hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, _bstr_("a:b"), 3);
ok(hr == E_INVALIDARG, "got %08x\n", hr); EXPECT_HR(hr, E_INVALIDARG);
/* only local name is an error too */ /* only local name is an error too */
hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, NULL, 0); hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, NULL, 0);
ok(hr == E_INVALIDARG, "got %08x\n", hr); EXPECT_HR(hr, E_INVALIDARG);
hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1); hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1);
ok(hr == S_OK, "got %08x\n", hr); EXPECT_HR(hr, S_OK);
V_VT(&dest) = VT_EMPTY; V_VT(&dest) = VT_EMPTY;
hr = IMXWriter_get_output(writer, &dest); hr = IMXWriter_get_output(writer, &dest);
ok(hr == S_OK, "got %08x\n", hr); EXPECT_HR(hr, S_OK);
ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest)); ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
ok(!lstrcmpW(_bstr_("<><b></b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest))); ok(!lstrcmpW(_bstr_("<><b></b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
VariantClear(&dest); VariantClear(&dest);
hr = ISAXContentHandler_endDocument(content); hr = ISAXContentHandler_endDocument(content);
ok(hr == S_OK, "got %08x\n", hr); EXPECT_HR(hr, S_OK);
V_VT(&dest) = VT_EMPTY;
hr = IMXWriter_put_output(writer, dest);
EXPECT_HR(hr, S_OK);
hr = ISAXContentHandler_startDocument(content);
EXPECT_HR(hr, S_OK);
hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("abcdef"), 3, NULL);
EXPECT_HR(hr, S_OK);
V_VT(&dest) = VT_EMPTY;
hr = IMXWriter_get_output(writer, &dest);
EXPECT_HR(hr, S_OK);
ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
ok(!lstrcmpW(_bstr_("<abc>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
VariantClear(&dest);
ISAXContentHandler_Release(content); ISAXContentHandler_Release(content);
IMXWriter_Release(writer); IMXWriter_Release(writer);