diff --git a/src/libsync/networkjobs.cpp b/src/libsync/networkjobs.cpp index 18837ea8b1..7e92d96c14 100644 --- a/src/libsync/networkjobs.cpp +++ b/src/libsync/networkjobs.cpp @@ -363,6 +363,7 @@ bool LsColXMLParser::parse( const QByteArray& xml, QHash *sizes bool currentPropsHaveHttp200 = false; bool insidePropstat = false; bool insideProp = false; + bool insideMultiStatus = false; while (!reader.atEnd()) { QXmlStreamReader::TokenType type = reader.readNext(); @@ -384,6 +385,9 @@ bool LsColXMLParser::parse( const QByteArray& xml, QHash *sizes } else if (name == QLatin1String("prop")) { insideProp = true; continue; + } else if (name == QLatin1String("multistatus")) { + insideMultiStatus = true; + continue; } } @@ -428,7 +432,10 @@ bool LsColXMLParser::parse( const QByteArray& xml, QHash *sizes if (reader.hasError()) { // XML Parser error? Whatever had been emitted before will come as directoryListingIterated - qDebug() << "ERROR" << reader.errorString(); + qDebug() << "ERROR" << reader.errorString() << xml; + return false; + } else if (!insideMultiStatus) { + qDebug() << "ERROR no WebDAV response?" << xml; return false; } else { emit directoryListingSubfolders(folders); diff --git a/test/testxmlparse.h b/test/testxmlparse.h index 065d5cf6de..add06cdd8c 100644 --- a/test/testxmlparse.h +++ b/test/testxmlparse.h @@ -197,6 +197,28 @@ private slots: QVERIFY(_subdirs.size() == 0); } + void testParserEmptyXmlNoDav() { + const QByteArray testXml = "I am under construction"; + + LsColXMLParser parser; + + connect( &parser, SIGNAL(directoryListingSubfolders(const QStringList&)), + this, SLOT(slotDirectoryListingSubFolders(const QStringList&)) ); + connect( &parser, SIGNAL(directoryListingIterated(const QString&, const QMap&)), + this, SLOT(slotDirectoryListingIterated(const QString&, const QMap&)) ); + connect( &parser, SIGNAL(finishedWithoutError()), + this, SLOT(slotFinishedSuccessfully()) ); + + QHash sizes; + QVERIFY(false == parser.parse( testXml, &sizes )); // verify false + + QVERIFY(!_success); + QVERIFY(sizes.size() == 0 ); // No quota info in the XML + + QVERIFY(_items.size() == 0 ); // FIXME: We should change the parser to not emit during parsing but at the end + QVERIFY(_subdirs.size() == 0); + } + void testParserEmptyXml() { const QByteArray testXml = "";