Module: wine Branch: master Commit: 3cd0bfd4a74697b67790cbd2666554af8853ecc9 URL: https://gitlab.winehq.org/wine/wine/-/commit/3cd0bfd4a74697b67790cbd2666554a...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Thu Sep 15 09:52:55 2022 +0300
xmllite/writer: Handle empty local name in WriteAttributeString().
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com
---
dlls/xmllite/tests/writer.c | 10 +++++++--- dlls/xmllite/writer.c | 30 +++++++++++++++--------------- 2 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/dlls/xmllite/tests/writer.c b/dlls/xmllite/tests/writer.c index 59950ae22fd..ceadb4c937e 100644 --- a/dlls/xmllite/tests/writer.c +++ b/dlls/xmllite/tests/writer.c @@ -1580,8 +1580,8 @@ static void test_WriteAttributeString(void) { NULL, NULL, L"http://www.w3.org/2000/xmlns/", L"defuri", "<e />", "<e", E_INVALIDARG }, { L"", L"a", L"http://www.w3.org/2000/xmlns/", L"defuri", "<e />", "<e", WR_E_XMLNSPREFIXDECLARATION, 1, 1, 1 }, { L"", NULL, L"http://www.w3.org/2000/xmlns/", L"defuri", "<e />", "<e", E_INVALIDARG }, - { L"", L"", L"http://www.w3.org/2000/xmlns/", L"defuri", "<e />", "<e", E_INVALIDARG, 1, 1, 1 }, - { NULL, L"", L"http://www.w3.org/2000/xmlns/", L"defuri", "<e />", "<e", E_INVALIDARG, 1, 1, 1 }, + { L"", L"", L"http://www.w3.org/2000/xmlns/", L"defuri", "<e />", "<e", E_INVALIDARG }, + { NULL, L"", L"http://www.w3.org/2000/xmlns/", L"defuri", "<e />", "<e", E_INVALIDARG }, { L"prefix", L"a", L"http://www.w3.org/2000/xmlns/", L"defuri", "<e />", "<e", WR_E_XMLNSURIDECLARATION, 1, 1, 1 }, { L"prefix", NULL, L"http://www.w3.org/2000/xmlns/", L"defuri", "<e />", "<e", E_INVALIDARG }, { L"prefix", NULL, NULL, L"b", "<e />", "<e", E_INVALIDARG }, @@ -1619,6 +1619,8 @@ static void test_WriteAttributeString(void)
for (i = 0; i < ARRAY_SIZE(attribute_tests); ++i) { + winetest_push_context("Test %u", i); + stream = writer_set_output(writer);
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit); @@ -1630,7 +1632,7 @@ static void test_WriteAttributeString(void) hr = IXmlWriter_WriteAttributeString(writer, attribute_tests[i].prefix, attribute_tests[i].local, attribute_tests[i].uri, attribute_tests[i].value); todo_wine_if(attribute_tests[i].todo_hr) - ok(hr == attribute_tests[i].hr, "%u: unexpected hr %#lx, expected %#lx.\n", i, hr, attribute_tests[i].hr); + ok(hr == attribute_tests[i].hr, "Unexpected hr %#lx, expected %#lx.\n", hr, attribute_tests[i].hr);
hr = IXmlWriter_Flush(writer); ok(hr == S_OK, "Failed to flush, hr %#lx.\n", hr); @@ -1645,6 +1647,8 @@ static void test_WriteAttributeString(void)
check_output(stream, attribute_tests[i].output, attribute_tests[i].todo, __LINE__); IStream_Release(stream); + + winetest_pop_context(); }
/* With namespaces */ diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c index 95e56bfd864..423cf9670d8 100644 --- a/dlls/xmllite/writer.c +++ b/dlls/xmllite/writer.c @@ -912,21 +912,21 @@ static BOOL is_valid_xml_space_value(const WCHAR *value) static HRESULT WINAPI xmlwriter_WriteAttributeString(IXmlWriter *iface, LPCWSTR prefix, LPCWSTR local, LPCWSTR uri, LPCWSTR value) { - xmlwriter *This = impl_from_IXmlWriter(iface); + xmlwriter *writer = impl_from_IXmlWriter(iface); BOOL is_xmlns_prefix, is_xmlns_local; int prefix_len, local_len; struct ns *ns; HRESULT hr;
- TRACE("%p %s %s %s %s\n", This, debugstr_w(prefix), debugstr_w(local), debugstr_w(uri), debugstr_w(value)); + TRACE("%p, %s, %s, %s, %s.\n", iface, debugstr_w(prefix), debugstr_w(local), debugstr_w(uri), debugstr_w(value));
- switch (This->state) + switch (writer->state) { case XmlWriterState_Initial: return E_UNEXPECTED; case XmlWriterState_Ready: case XmlWriterState_DocClosed: - This->state = XmlWriterState_DocClosed; + writer->state = XmlWriterState_DocClosed; return WR_E_INVALIDACTION; case XmlWriterState_InvalidEncoding: return MX_E_ENCODING; @@ -939,7 +939,7 @@ static HRESULT WINAPI xmlwriter_WriteAttributeString(IXmlWriter *iface, LPCWSTR if (is_xmlns_prefix && is_empty_string(uri) && is_empty_string(local)) return WR_E_NSPREFIXDECLARED;
- if (!local) + if (is_empty_string(local)) return E_INVALIDARG;
/* Validate prefix and local name */ @@ -954,7 +954,7 @@ static HRESULT WINAPI xmlwriter_WriteAttributeString(IXmlWriter *iface, LPCWSTR /* Trivial case, no prefix. */ if (prefix_len == 0 && is_empty_string(uri)) { - write_output_attribute(This, prefix, prefix_len, local, local_len, value); + write_output_attribute(writer, prefix, prefix_len, local, local_len, value); return S_OK; }
@@ -969,7 +969,7 @@ static HRESULT WINAPI xmlwriter_WriteAttributeString(IXmlWriter *iface, LPCWSTR if (!is_empty_string(uri)) return WR_E_XMLPREFIXDECLARATION;
- write_output_attribute(This, prefix, prefix_len, local, local_len, value); + write_output_attribute(writer, prefix, prefix_len, local, local_len, value);
return S_OK; } @@ -980,11 +980,11 @@ static HRESULT WINAPI xmlwriter_WriteAttributeString(IXmlWriter *iface, LPCWSTR return WR_E_XMLNSPREFIXDECLARATION;
/* Look for exact match defined in current element, and write it out. */ - if (!(ns = writer_find_ns_current(This, prefix, value))) - ns = writer_push_ns(This, local, local_len, value); + if (!(ns = writer_find_ns_current(writer, prefix, value))) + ns = writer_push_ns(writer, local, local_len, value); ns->emitted = TRUE;
- write_output_attribute(This, L"xmlns", 5, local, local_len, value); + write_output_attribute(writer, L"xmlns", 5, local, local_len, value);
return S_OK; } @@ -992,11 +992,11 @@ static HRESULT WINAPI xmlwriter_WriteAttributeString(IXmlWriter *iface, LPCWSTR /* Ignore prefix if URI wasn't specified. */ if (is_xmlns_local && is_empty_string(uri)) { - write_output_attribute(This, NULL, 0, L"xmlns", 5, value); + write_output_attribute(writer, NULL, 0, L"xmlns", 5, value); return S_OK; }
- if (!(ns = writer_find_ns(This, prefix, uri))) + if (!(ns = writer_find_ns(writer, prefix, uri))) { if (is_empty_string(prefix) && !is_empty_string(uri)) { @@ -1004,13 +1004,13 @@ static HRESULT WINAPI xmlwriter_WriteAttributeString(IXmlWriter *iface, LPCWSTR return E_NOTIMPL; } if (!is_empty_string(uri)) - ns = writer_push_ns(This, prefix, prefix_len, uri); + ns = writer_push_ns(writer, prefix, prefix_len, uri); }
if (ns) - write_output_attribute(This, ns->prefix, ns->prefix_len, local, local_len, value); + write_output_attribute(writer, ns->prefix, ns->prefix_len, local, local_len, value); else - write_output_attribute(This, prefix, prefix_len, local, local_len, value); + write_output_attribute(writer, prefix, prefix_len, local, local_len, value);
return S_OK; }