Merge pull request #4919 from nextcloud/bugfix/accept-valid-content-types

Accept valid lsColJob reply XML content types
This commit is contained in:
Matthieu Gallien 2022-09-12 15:20:42 +02:00 committed by GitHub
commit 88464a097d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 8 deletions

View file

@ -583,14 +583,20 @@ void DiscoverySingleDirectoryJob::lsJobFinishedWithoutErrorSlot()
void DiscoverySingleDirectoryJob::lsJobFinishedWithErrorSlot(QNetworkReply *r) void DiscoverySingleDirectoryJob::lsJobFinishedWithErrorSlot(QNetworkReply *r)
{ {
QString contentType = r->header(QNetworkRequest::ContentTypeHeader).toString(); const auto contentType = r->header(QNetworkRequest::ContentTypeHeader).toString();
int httpCode = r->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); const auto invalidContentType = !contentType.contains("application/xml; charset=utf-8") &&
QString msg = r->errorString(); !contentType.contains("application/xml; charset=\"utf-8\"") &&
!contentType.contains("text/xml; charset=utf-8") &&
!contentType.contains("text/xml; charset=\"utf-8\"");
const auto httpCode = r->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
auto msg = r->errorString();
qCWarning(lcDiscovery) << "LSCOL job error" << r->errorString() << httpCode << r->error(); qCWarning(lcDiscovery) << "LSCOL job error" << r->errorString() << httpCode << r->error();
if (r->error() == QNetworkReply::NoError
&& !contentType.contains("application/xml; charset=utf-8")) { if (r->error() == QNetworkReply::NoError && invalidContentType) {
msg = tr("Server error: PROPFIND reply is not XML formatted!"); msg = tr("Server error: PROPFIND reply is not XML formatted!");
} }
emit finished(HttpError{ httpCode, msg }); emit finished(HttpError{ httpCode, msg });
deleteLater(); deleteLater();
} }

View file

@ -395,9 +395,14 @@ bool LsColJob::finished()
qCInfo(lcLsColJob) << "LSCOL of" << reply()->request().url() << "FINISHED WITH STATUS" qCInfo(lcLsColJob) << "LSCOL of" << reply()->request().url() << "FINISHED WITH STATUS"
<< replyStatusString(); << replyStatusString();
QString contentType = reply()->header(QNetworkRequest::ContentTypeHeader).toString(); const auto contentType = reply()->header(QNetworkRequest::ContentTypeHeader).toString();
int httpCode = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); const auto httpCode = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (httpCode == 207 && contentType.contains("application/xml; charset=utf-8")) { const auto validContentType = contentType.contains("application/xml; charset=utf-8") ||
contentType.contains("application/xml; charset=\"utf-8\"") ||
contentType.contains("text/xml; charset=utf-8") ||
contentType.contains("text/xml; charset=\"utf-8\"");
if (httpCode == 207 && validContentType) {
LsColXMLParser parser; LsColXMLParser parser;
connect(&parser, &LsColXMLParser::directoryListingSubfolders, connect(&parser, &LsColXMLParser::directoryListingSubfolders,
this, &LsColJob::directoryListingSubfolders); this, &LsColJob::directoryListingSubfolders);