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 Change-Id: I0160b65880756a2be541e9f55dc79557fcb1f09f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit ccd8a496cf46313ea0df9fe70f4e4b57f9434b24) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
f699962821
commit
ce3ca69dc6
@ -721,7 +721,7 @@ QXmlStreamReader::TokenType QXmlStreamReader::tokenType() const
|
||||
bool QXmlStreamReader::readNextStartElement()
|
||||
{
|
||||
while (readNext() != Invalid) {
|
||||
if (isEndElement())
|
||||
if (isEndElement() || isEndDocument())
|
||||
return false;
|
||||
else if (isStartElement())
|
||||
return true;
|
||||
|
@ -1147,6 +1147,10 @@ void tst_QXmlStream::readNextStartElement() const
|
||||
}
|
||||
|
||||
QCOMPARE(amountOfB, 2);
|
||||
|
||||
// well-formed document end follows
|
||||
QVERIFY(!reader.readNextStartElement());
|
||||
QCOMPARE(reader.error(), QXmlStreamReader::NoError);
|
||||
}
|
||||
|
||||
void tst_QXmlStream::readElementText() const
|
||||
|
Loading…
x
Reference in New Issue
Block a user