Commit 2d5d3a89 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

xmllite/writer: Fix "xml:space" output.

parent 6fbf6c33
...@@ -1637,6 +1637,12 @@ static void test_WriteAttributeString(void) ...@@ -1637,6 +1637,12 @@ static void test_WriteAttributeString(void)
{ "prefix", "xmlns", "uri", "", "<e prefix:xmlns=\"\" xmlns:prefix=\"uri\" />", "<e prefix:xmlns=\"\"" }, { "prefix", "xmlns", "uri", "", "<e prefix:xmlns=\"\" xmlns:prefix=\"uri\" />", "<e prefix:xmlns=\"\"" },
{ "prefix", "xmlns", NULL, "uri", "<e xmlns=\"uri\" />", "<e xmlns=\"uri\"" }, { "prefix", "xmlns", NULL, "uri", "<e xmlns=\"uri\" />", "<e xmlns=\"uri\"" },
{ "prefix", "xmlns", "", "uri", "<e xmlns=\"uri\" />", "<e xmlns=\"uri\"" }, { "prefix", "xmlns", "", "uri", "<e xmlns=\"uri\" />", "<e xmlns=\"uri\"" },
{ "xml", "space", NULL, "preserve", "<e xml:space=\"preserve\" />", "<e xml:space=\"preserve\"" },
{ "xml", "space", "", "preserve", "<e xml:space=\"preserve\" />", "<e xml:space=\"preserve\"" },
{ "xml", "space", NULL, "default", "<e xml:space=\"default\" />", "<e xml:space=\"default\"" },
{ "xml", "space", "", "default", "<e xml:space=\"default\" />", "<e xml:space=\"default\"" },
{ "xml", "a", NULL, "value", "<e xml:a=\"value\" />", "<e xml:a=\"value\"" },
{ "xml", "a", "", "value", "<e xml:a=\"value\" />", "<e xml:a=\"value\"" },
/* Autogenerated prefix names. */ /* Autogenerated prefix names. */
{ NULL, "a", "defuri", NULL, "<e p1:a=\"\" xmlns:p1=\"defuri\" />", "<e p1:a=\"\"", S_OK, 1, 1, 1 }, { NULL, "a", "defuri", NULL, "<e p1:a=\"\" xmlns:p1=\"defuri\" />", "<e p1:a=\"\"", S_OK, 1, 1, 1 },
...@@ -1655,6 +1661,7 @@ static void test_WriteAttributeString(void) ...@@ -1655,6 +1661,7 @@ static void test_WriteAttributeString(void)
{ "prefix", NULL, "http://www.w3.org/2000/xmlns/", "defuri", "<e />", "<e", E_INVALIDARG }, { "prefix", NULL, "http://www.w3.org/2000/xmlns/", "defuri", "<e />", "<e", E_INVALIDARG },
{ "prefix", NULL, NULL, "b", "<e />", "<e", E_INVALIDARG }, { "prefix", NULL, NULL, "b", "<e />", "<e", E_INVALIDARG },
{ "prefix", NULL, "uri", NULL, "<e />", "<e", E_INVALIDARG }, { "prefix", NULL, "uri", NULL, "<e />", "<e", E_INVALIDARG },
{ "xml", NULL, NULL, "value", "<e />", "<e", E_INVALIDARG },
{ "xmlns", "a", "defuri", NULL, "<e />", "<e", WR_E_XMLNSPREFIXDECLARATION }, { "xmlns", "a", "defuri", NULL, "<e />", "<e", WR_E_XMLNSPREFIXDECLARATION },
{ "xmlns", "a", "b", "uri", "<e />", "<e", WR_E_XMLNSPREFIXDECLARATION }, { "xmlns", "a", "b", "uri", "<e />", "<e", WR_E_XMLNSPREFIXDECLARATION },
{ NULL, "xmlns", "uri", NULL, "<e />", "<e", WR_E_XMLNSPREFIXDECLARATION, 0, 0, 1 }, { NULL, "xmlns", "uri", NULL, "<e />", "<e", WR_E_XMLNSPREFIXDECLARATION, 0, 0, 1 },
...@@ -1666,6 +1673,13 @@ static void test_WriteAttributeString(void) ...@@ -1666,6 +1673,13 @@ static void test_WriteAttributeString(void)
{ "xmlns", NULL, "", "uri", "<e />", "<e", WR_E_NSPREFIXDECLARED }, { "xmlns", NULL, "", "uri", "<e />", "<e", WR_E_NSPREFIXDECLARED },
{ "xmlns", "", NULL, "uri", "<e />", "<e", WR_E_NSPREFIXDECLARED }, { "xmlns", "", NULL, "uri", "<e />", "<e", WR_E_NSPREFIXDECLARED },
{ "xmlns", "", "", "uri", "<e />", "<e", WR_E_NSPREFIXDECLARED }, { "xmlns", "", "", "uri", "<e />", "<e", WR_E_NSPREFIXDECLARED },
{ "xml", "space", "", "value", "<e />", "<e", WR_E_INVALIDXMLSPACE },
{ "xml", "space", NULL, "value", "<e />", "<e", WR_E_INVALIDXMLSPACE },
{ "xml", "a", "uri", "value", "<e />", "<e", WR_E_XMLPREFIXDECLARATION },
{ "xml", "space", NULL, "preServe", "<e />", "<e", WR_E_INVALIDXMLSPACE },
{ "xml", "space", NULL, "defAult", "<e />", "<e", WR_E_INVALIDXMLSPACE },
{ "xml", "space", NULL, NULL, "<e />", "<e", WR_E_INVALIDXMLSPACE },
{ "xml", "space", NULL, "", "<e />", "<e", WR_E_INVALIDXMLSPACE },
}; };
IXmlWriter *writer; IXmlWriter *writer;
......
...@@ -825,10 +825,23 @@ static void write_output_attribute(xmlwriter *writer, const WCHAR *prefix, int p ...@@ -825,10 +825,23 @@ static void write_output_attribute(xmlwriter *writer, const WCHAR *prefix, int p
write_output_buffer_quoted(writer->output, value, -1); write_output_buffer_quoted(writer->output, value, -1);
} }
static BOOL is_valid_xml_space_value(const WCHAR *value)
{
static const WCHAR preserveW[] = {'p','r','e','s','e','r','v','e',0};
static const WCHAR defaultW[] = {'d','e','f','a','u','l','t',0};
if (!value)
return FALSE;
return !strcmpW(value, preserveW) || !strcmpW(value, defaultW);
}
static HRESULT WINAPI xmlwriter_WriteAttributeString(IXmlWriter *iface, LPCWSTR prefix, static HRESULT WINAPI xmlwriter_WriteAttributeString(IXmlWriter *iface, LPCWSTR prefix,
LPCWSTR local, LPCWSTR uri, LPCWSTR value) LPCWSTR local, LPCWSTR uri, LPCWSTR value)
{ {
static const WCHAR spaceattrW[] = {'s','p','a','c','e',0};
static const WCHAR xmlnsW[] = {'x','m','l','n','s',0}; static const WCHAR xmlnsW[] = {'x','m','l','n','s',0};
static const WCHAR xmlW[] = {'x','m','l',0};
xmlwriter *This = impl_from_IXmlWriter(iface); xmlwriter *This = impl_from_IXmlWriter(iface);
int prefix_len, local_len; int prefix_len, local_len;
BOOL is_xmlns_prefix; BOOL is_xmlns_prefix;
...@@ -873,6 +886,22 @@ static HRESULT WINAPI xmlwriter_WriteAttributeString(IXmlWriter *iface, LPCWSTR ...@@ -873,6 +886,22 @@ static HRESULT WINAPI xmlwriter_WriteAttributeString(IXmlWriter *iface, LPCWSTR
return S_OK; return S_OK;
} }
/* Predefined "xml" prefix. */
if (prefix_len && !strcmpW(prefix, xmlW))
{
/* Valid "space" value is enforced. */
if (!strcmpW(local, spaceattrW) && !is_valid_xml_space_value(value))
return WR_E_INVALIDXMLSPACE;
/* Redefinition is not allowed. */
if (!is_empty_string(uri))
return WR_E_XMLPREFIXDECLARATION;
write_output_attribute(This, prefix, prefix_len, local, local_len, value);
return S_OK;
}
if (is_xmlns_prefix || (prefix_len == 0 && uri && !strcmpW(uri, xmlnsuriW))) if (is_xmlns_prefix || (prefix_len == 0 && uri && !strcmpW(uri, xmlnsuriW)))
{ {
if (prefix_len && !is_empty_string(uri)) if (prefix_len && !is_empty_string(uri))
......
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