diff options
-rw-r--r-- | src/corelib/xml/qxmlstream.cpp | 3 | ||||
-rw-r--r-- | tests/auto/qxmlstream/tst_qxmlstream.cpp | 17 |
2 files changed, 19 insertions, 1 deletions
diff --git a/src/corelib/xml/qxmlstream.cpp b/src/corelib/xml/qxmlstream.cpp index 1bf00b8..ae12007 100644 --- a/src/corelib/xml/qxmlstream.cpp +++ b/src/corelib/xml/qxmlstream.cpp @@ -3716,7 +3716,8 @@ void QXmlStreamWriter::writeProcessingInstruction(const QString &target, const Q { Q_D(QXmlStreamWriter); Q_ASSERT(!data.contains(QLatin1String("?>"))); - d->finishStartElement(); + if (!d->finishStartElement(false) && d->autoFormatting) + d->indent(d->tagStack.size()); d->write("<?"); d->write(target); if (!data.isNull()) { diff --git a/tests/auto/qxmlstream/tst_qxmlstream.cpp b/tests/auto/qxmlstream/tst_qxmlstream.cpp index 3c5358c..f93d4fc 100644 --- a/tests/auto/qxmlstream/tst_qxmlstream.cpp +++ b/tests/auto/qxmlstream/tst_qxmlstream.cpp @@ -546,6 +546,7 @@ private slots: void writerHangs() const; void writerAutoFormattingWithComments() const; void writerAutoFormattingWithTabs() const; + void writerAutoFormattingWithProcessingInstructions() const; void writerAutoEmptyTags() const; void writeAttributesWithSpace() const; void addExtraNamespaceDeclarations(); @@ -1030,6 +1031,22 @@ void tst_QXmlStream::writerAutoFormattingWithTabs() const QCOMPARE(buffer.buffer().data(), str); } +void tst_QXmlStream::writerAutoFormattingWithProcessingInstructions() const +{ + QBuffer buffer; + buffer.open(QIODevice::WriteOnly); + + QXmlStreamWriter writer(&buffer); + writer.setAutoFormatting(true); + writer.writeStartDocument(); + writer.writeProcessingInstruction("B", "C"); + writer.writeStartElement("A"); + writer.writeEndElement(); + writer.writeEndDocument(); + const char *str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?B C?>\n<A/>\n"; + QCOMPARE(buffer.buffer().data(), str); +} + /*! Task 204822 */ |