Nikolay Sivov : xmllite/writer: Do not indent after just BOM has been written.

Alexandre Julliard julliard at winehq.org
Mon Jul 24 15:51:19 CDT 2017


Module: wine
Branch: master
Commit: a6d6bebede744c9e7f93ef315883909fc93c6f20
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=a6d6bebede744c9e7f93ef315883909fc93c6f20

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Sun Jul 23 14:55:46 2017 +0300

xmllite/writer: Do not indent after just BOM has been written.

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/xmllite/tests/writer.c | 5 ++++-
 dlls/xmllite/writer.c       | 7 +++++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/dlls/xmllite/tests/writer.c b/dlls/xmllite/tests/writer.c
index b82e154..8ef2e70 100644
--- a/dlls/xmllite/tests/writer.c
+++ b/dlls/xmllite/tests/writer.c
@@ -648,6 +648,8 @@ static void test_bom(void)
     hr = IXmlWriter_SetOutput(writer, output);
     ok(hr == S_OK, "got 0x%08x\n", hr);
 
+    writer_set_property(writer, XmlWriterProperty_Indent);
+
     hr = IXmlWriter_WriteElementString(writer, NULL, aW, NULL, NULL);
     ok(hr == S_OK, "got 0x%08x\n", hr);
 
@@ -658,7 +660,8 @@ static void test_bom(void)
     ok(hr == S_OK, "got 0x%08x\n", hr);
 
     ptr = GlobalLock(hglobal);
-    ok(ptr[0] == 0xff && ptr[1] == 0xfe, "got %x,%x\n", ptr[0], ptr[1]);
+    ok(ptr[0] == 0xff && ptr[1] == 0xfe && ptr[2] == '<', "Unexpected output: %#x,%#x,%#x\n",
+            ptr[0], ptr[1], ptr[2]);
     GlobalUnlock(hglobal);
 
     IUnknown_Release(output);
diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c
index ac28c47..9e99338 100644
--- a/dlls/xmllite/writer.c
+++ b/dlls/xmllite/writer.c
@@ -447,7 +447,9 @@ static void write_node_indent(xmlwriter *writer)
     if (!writer->indent)
         return;
 
-    if (writer->output->buffer.written)
+    /* Do state check to prevent newline inserted after BOM. It is assumed that
+       state does not change between writing BOM and inserting indentation. */
+    if (writer->output->buffer.written && writer->state != XmlWriterState_Ready)
         write_output_buffer(writer->output, crlfW, ARRAY_SIZE(crlfW));
     while (indent_level--)
         write_output_buffer(writer->output, dblspaceW, ARRAY_SIZE(dblspaceW));
@@ -1208,12 +1210,13 @@ static HRESULT WINAPI xmlwriter_WriteStartElement(IXmlWriter *iface, LPCWSTR pre
         return E_OUTOFMEMORY;
 
     write_encoding_bom(This);
+    write_node_indent(This);
+
     This->state = XmlWriterState_ElemStarted;
     This->starttagopen = TRUE;
 
     push_element(This, element);
 
-    write_node_indent(This);
     write_output_buffer(This->output, ltW, ARRAY_SIZE(ltW));
     write_output_qname(This->output, prefix, local_name);
     writer_inc_indent(This);




More information about the wine-cvs mailing list