QXmlStreamReader::readNextStartElement() - return false on document end
The method reads the next element in a loop, as long as valid elements exist. Within the loop, it returns - false if the end of an element has been reached - true if a new element has started When the document end has been reached, the loop continues, until readNext() returns Invalid. Then, PrematureEndOfDocumentError is launched. This is wrong, because reading beyond the document end is caused by a missing return condition in the loop. => Treat document end like element end and return false without reading beyond it. => Test correct behavior in tst_QXmlStream::readNextStartElement() Fixes: QTBUG-25944 Pick-to: 6.6 6.5 6.2 Change-Id: I0160b65880756a2be541e9f55dc79557fcb1f09f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
56bd5d60c9
commit
ccd8a496cf
@ -721,7 +721,7 @@ QXmlStreamReader::TokenType QXmlStreamReader::tokenType() const
|
|||||||
bool QXmlStreamReader::readNextStartElement()
|
bool QXmlStreamReader::readNextStartElement()
|
||||||
{
|
{
|
||||||
while (readNext() != Invalid) {
|
while (readNext() != Invalid) {
|
||||||
if (isEndElement())
|
if (isEndElement() || isEndDocument())
|
||||||
return false;
|
return false;
|
||||||
else if (isStartElement())
|
else if (isStartElement())
|
||||||
return true;
|
return true;
|
||||||
|
@ -1147,6 +1147,10 @@ void tst_QXmlStream::readNextStartElement() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
QCOMPARE(amountOfB, 2);
|
QCOMPARE(amountOfB, 2);
|
||||||
|
|
||||||
|
// well-formed document end follows
|
||||||
|
QVERIFY(!reader.readNextStartElement());
|
||||||
|
QCOMPARE(reader.error(), QXmlStreamReader::NoError);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QXmlStream::readElementText() const
|
void tst_QXmlStream::readElementText() const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user