Fix QXmlStreamWriter xmlns attribute placement

Done-by: Eugenio Rustico
Change-Id: Ibd6aa6cc8be9090a4fad4f96628086d8a498b8e0
Fixes: QTBUG-63434
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
hjk 2018-09-27 12:46:13 +02:00
parent 1d09b0d1b2
commit f286027e6b
2 changed files with 33 additions and 1 deletions

View File

@ -3956,13 +3956,13 @@ void QXmlStreamWriter::writeCurrentToken(const QXmlStreamReader &reader)
writeEndDocument();
break;
case QXmlStreamReader::StartElement: {
writeStartElement(reader.namespaceUri().toString(), reader.name().toString());
QXmlStreamNamespaceDeclarations namespaceDeclarations = reader.namespaceDeclarations();
for (int i = 0; i < namespaceDeclarations.size(); ++i) {
const QXmlStreamNamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.at(i);
writeNamespace(namespaceDeclaration.namespaceUri().toString(),
namespaceDeclaration.prefix().toString());
}
writeStartElement(reader.namespaceUri().toString(), reader.name().toString());
writeAttributes(reader.attributes());
} break;
case QXmlStreamReader::EndElement:

View File

@ -577,6 +577,8 @@ private slots:
void invalidStringCharacters() const;
void hasError() const;
void readBack() const;
void roundTrip() const;
void roundTrip_data() const;
private:
static QByteArray readFile(const QString &filename);
@ -1741,5 +1743,35 @@ void tst_QXmlStream::readBack() const
}
}
void tst_QXmlStream::roundTrip_data() const
{
QTest::addColumn<QString>("in");
QTest::newRow("QTBUG-63434") <<
"<?xml version=\"1.0\"?>"
"<root>"
"<father>"
"<child xmlns:unknown=\"http://mydomain\">Text</child>"
"</father>"
"</root>\n";
}
void tst_QXmlStream::roundTrip() const
{
QFETCH(QString, in);
QString out;
QXmlStreamReader reader(in);
QXmlStreamWriter writer(&out);
while (!reader.atEnd()) {
reader.readNext();
QVERIFY(!reader.hasError());
writer.writeCurrentToken(reader);
QVERIFY(!writer.hasError());
}
QCOMPARE(out, in);
}
#include "tst_qxmlstream.moc"
// vim: et:ts=4:sw=4:sts=4