fix: invalid bres url may cause webengine to crash. such as bres://upload.wikimedia.org/wikipedia/commons/2/23/Icons-mini-file_acrobat.gif

This commit is contained in:
xiaoyifang 2022-01-09 11:36:48 +08:00
parent bd6cc8b9c9
commit 3f11826918
2 changed files with 7 additions and 5 deletions

View file

@ -518,7 +518,7 @@ void ArticleView::loadFinished( bool )
{ {
setZoomFactor(cfg.preferences.zoomFactor); setZoomFactor(cfg.preferences.zoomFactor);
QUrl url = ui.definition->url(); QUrl url = ui.definition->url();
qDebug() << "article view loaded url:" << url; qDebug() << "article view loaded url:" << url.url ().left (200);
QVariant userDataVariant = ui.definition->property("currentArticle"); QVariant userDataVariant = ui.definition->property("currentArticle");

View file

@ -8,16 +8,18 @@ void ResourceSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
QUrl url = requestJob->requestUrl(); QUrl url = requestJob->requestUrl();
QNetworkRequest request; QNetworkRequest request;
request.setUrl( url ); request.setUrl(url);
QNetworkReply *reply = this->mManager.createRequest(QNetworkAccessManager::GetOperation, request, NULL); QNetworkReply *reply = this->mManager.createRequest(QNetworkAccessManager::GetOperation, request, NULL);
connect(reply, &QNetworkReply::finished, requestJob, [=]() { connect(reply, &QNetworkReply::finished, requestJob, [=]() {
if (reply->error() == QNetworkReply::ContentNotFoundError) { if (reply->error() == QNetworkReply::ContentNotFoundError) {
requestJob->fail(QWebEngineUrlRequestJob::UrlNotFound); requestJob->fail(QWebEngineUrlRequestJob::UrlNotFound);
return; return;
} }
qDebug() << "resource scheme handler receive finished signal:" << reply->request().url(); if (reply->error() != QNetworkReply::NoError) {
qDebug() << "resource handler failed:" << reply->error() << ":" << reply->request().url();
requestJob->fail(QWebEngineUrlRequestJob::RequestFailed);
return;
}
QMimeType mineType = db.mimeTypeForUrl(url); QMimeType mineType = db.mimeTypeForUrl(url);
QString contentType = mineType.name(); QString contentType = mineType.name();
// Reply segment // Reply segment