From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/xmllite/tests/writer.c | 26 +++++++++++++++++++++++++- dlls/xmllite/writer.c | 20 ++++++++++---------- 2 files changed, 35 insertions(+), 11 deletions(-)
diff --git a/dlls/xmllite/tests/writer.c b/dlls/xmllite/tests/writer.c index a000bde6d80..c76f3708fca 100644 --- a/dlls/xmllite/tests/writer.c +++ b/dlls/xmllite/tests/writer.c @@ -1736,9 +1736,33 @@ static void test_WriteFullEndElement(void) "<a>\r\n" " <a></a>\r\n" "</a>"); + IStream_Release(stream);
- IXmlWriter_Release(writer); + /* Empty strings for prefix and uri. */ + stream = writer_set_output(writer); + + hr = IXmlWriter_SetProperty(writer, XmlWriterProperty_Indent, FALSE); + ok(hr == S_OK, "Failed to set property, hr %#lx.\n", hr); + + hr = IXmlWriter_WriteStartElement(writer, L"", L"a", NULL); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + hr = IXmlWriter_WriteStartElement(writer, NULL, L"b", L""); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + hr = IXmlWriter_WriteStartElement(writer, L"", L"c", L""); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + hr = IXmlWriter_WriteFullEndElement(writer); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + hr = IXmlWriter_WriteFullEndElement(writer); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + hr = IXmlWriter_WriteFullEndElement(writer); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_Flush(writer); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + CHECK_OUTPUT(stream, "<a><b><c></c></b></a>"); IStream_Release(stream); + + IXmlWriter_Release(writer); }
static void test_WriteCharEntity(void) diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c index 0a3717d426e..2ec1a3b12da 100644 --- a/dlls/xmllite/writer.c +++ b/dlls/xmllite/writer.c @@ -168,6 +168,11 @@ static inline void writer_free(const xmlwriter *writer, void *mem) m_free(writer->imalloc, mem); }
+static BOOL is_empty_string(const WCHAR *str) +{ + return !str || !*str; +} + static struct element *alloc_element(xmlwriter *writer, const WCHAR *prefix, const WCHAR *local) { struct element *ret; @@ -176,7 +181,7 @@ static struct element *alloc_element(xmlwriter *writer, const WCHAR *prefix, con ret = writer_alloc(writer, sizeof(*ret)); if (!ret) return ret;
- len = prefix ? lstrlenW(prefix) + 1 /* ':' */ : 0; + len = is_empty_string(prefix) ? 0 : lstrlenW(prefix) + 1 /* ':' */; len += lstrlenW(local);
ret->qname = writer_alloc(writer, (len + 1)*sizeof(WCHAR)); @@ -188,13 +193,13 @@ static struct element *alloc_element(xmlwriter *writer, const WCHAR *prefix, con }
ret->len = len; - if (prefix) + if (is_empty_string(prefix)) + ret->qname[0] = 0; + else { lstrcpyW(ret->qname, prefix); lstrcatW(ret->qname, L":"); } - else - ret->qname[0] = 0; lstrcatW(ret->qname, local); list_init(&ret->ns);
@@ -288,11 +293,6 @@ static struct ns *writer_push_ns(xmlwriter *writer, const WCHAR *prefix, int pre return ns; }
-static BOOL is_empty_string(const WCHAR *str) -{ - return !str || !*str; -} - static struct ns *writer_find_ns_current(const xmlwriter *writer, const WCHAR *prefix, const WCHAR *uri) { struct element *element; @@ -1676,7 +1676,7 @@ static HRESULT WINAPI xmlwriter_WriteStartElement(IXmlWriter *iface, LPCWSTR pre
writer_push_element(This, element);
- if (!ns && uri) + if (!ns && !is_empty_string(uri)) writer_push_ns(This, prefix, prefix_len, uri);
write_output_buffer_char(This->output, '<');