diff --git a/dlls/xmllite/tests/writer.c b/dlls/xmllite/tests/writer.c index b82e15477a9..8ef2e709793 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 ac28c47b3cb..9e993387986 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);