Commit 57497d12 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

xmllite/writer: Handle empty prefix and uri correctly in WriteStartElement().

parent 225e7b34
...@@ -1736,9 +1736,33 @@ static void test_WriteFullEndElement(void) ...@@ -1736,9 +1736,33 @@ static void test_WriteFullEndElement(void)
"<a>\r\n" "<a>\r\n"
" <a></a>\r\n" " <a></a>\r\n"
"</a>"); "</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); IStream_Release(stream);
IXmlWriter_Release(writer);
} }
static void test_WriteCharEntity(void) static void test_WriteCharEntity(void)
......
...@@ -168,6 +168,11 @@ static inline void writer_free(const xmlwriter *writer, void *mem) ...@@ -168,6 +168,11 @@ static inline void writer_free(const xmlwriter *writer, void *mem)
m_free(writer->imalloc, 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) static struct element *alloc_element(xmlwriter *writer, const WCHAR *prefix, const WCHAR *local)
{ {
struct element *ret; struct element *ret;
...@@ -176,7 +181,7 @@ static struct element *alloc_element(xmlwriter *writer, const WCHAR *prefix, con ...@@ -176,7 +181,7 @@ static struct element *alloc_element(xmlwriter *writer, const WCHAR *prefix, con
ret = writer_alloc(writer, sizeof(*ret)); ret = writer_alloc(writer, sizeof(*ret));
if (!ret) return ret; if (!ret) return ret;
len = prefix ? lstrlenW(prefix) + 1 /* ':' */ : 0; len = is_empty_string(prefix) ? 0 : lstrlenW(prefix) + 1 /* ':' */;
len += lstrlenW(local); len += lstrlenW(local);
ret->qname = writer_alloc(writer, (len + 1)*sizeof(WCHAR)); ret->qname = writer_alloc(writer, (len + 1)*sizeof(WCHAR));
...@@ -188,13 +193,13 @@ static struct element *alloc_element(xmlwriter *writer, const WCHAR *prefix, con ...@@ -188,13 +193,13 @@ static struct element *alloc_element(xmlwriter *writer, const WCHAR *prefix, con
} }
ret->len = len; ret->len = len;
if (prefix) if (is_empty_string(prefix))
ret->qname[0] = 0;
else
{ {
lstrcpyW(ret->qname, prefix); lstrcpyW(ret->qname, prefix);
lstrcatW(ret->qname, L":"); lstrcatW(ret->qname, L":");
} }
else
ret->qname[0] = 0;
lstrcatW(ret->qname, local); lstrcatW(ret->qname, local);
list_init(&ret->ns); list_init(&ret->ns);
...@@ -288,11 +293,6 @@ static struct ns *writer_push_ns(xmlwriter *writer, const WCHAR *prefix, int pre ...@@ -288,11 +293,6 @@ static struct ns *writer_push_ns(xmlwriter *writer, const WCHAR *prefix, int pre
return ns; 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) static struct ns *writer_find_ns_current(const xmlwriter *writer, const WCHAR *prefix, const WCHAR *uri)
{ {
struct element *element; struct element *element;
...@@ -1676,7 +1676,7 @@ static HRESULT WINAPI xmlwriter_WriteStartElement(IXmlWriter *iface, LPCWSTR pre ...@@ -1676,7 +1676,7 @@ static HRESULT WINAPI xmlwriter_WriteStartElement(IXmlWriter *iface, LPCWSTR pre
writer_push_element(This, element); writer_push_element(This, element);
if (!ns && uri) if (!ns && !is_empty_string(uri))
writer_push_ns(This, prefix, prefix_len, uri); writer_push_ns(This, prefix, prefix_len, uri);
write_output_buffer_char(This->output, '<'); write_output_buffer_char(This->output, '<');
......
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