From 691e60d72bbbea6211a36d079fd041080a28159a Mon Sep 17 00:00:00 2001 From: thez3ro Date: Thu, 13 Jul 2017 23:10:15 +0200 Subject: [PATCH] check if url is valid --- src/core/Entry.cpp | 24 +++++++++++++----------- src/gui/EditWidgetIcons.cpp | 6 ++++-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index cb4c8cff8..267c9ad2b 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -795,22 +795,24 @@ QString Entry::resolvePlaceholder(const QString& str) const QString Entry::resolveUrl(const QString& url) const { #ifdef WITH_XC_HTTP - QString newurl = url; + QString newUrl = url; if (!url.contains("://")) { // URL doesn't have a protocol, add https by default - newurl.prepend("https://"); + newUrl.prepend("https://"); } - QUrl uurl = QUrl(newurl); + QUrl tempUrl = QUrl(newUrl); - if (uurl.scheme() == "cmd") { - // URL is a cmd, hopefully the second argument is an URL - QStringList cmd = newurl.split(" "); - if (cmd.size() > 1) { - return resolveUrl(cmd[1].remove("'").remove("\"")); + if (tempUrl.isValid()) { + if (tempUrl.scheme() == "cmd") { + // URL is a cmd, hopefully the second argument is an URL + QStringList cmd = newUrl.split(" "); + if (cmd.size() > 1) { + return resolveUrl(cmd[1].remove("'").remove("\"")); + } + } else if (tempUrl.scheme() == "http" || tempUrl.scheme() == "https") { + // URL is nice + return tempUrl.url(); } - } else if (uurl.scheme() == "http" || uurl.scheme() == "https") { - // URL is nice - return uurl.url(); } #else Q_UNUSED(url); diff --git a/src/gui/EditWidgetIcons.cpp b/src/gui/EditWidgetIcons.cpp index b29699342..4c4c35c4b 100644 --- a/src/gui/EditWidgetIcons.cpp +++ b/src/gui/EditWidgetIcons.cpp @@ -226,7 +226,7 @@ void EditWidgetIcons::fetchFavicon(const QUrl& url) QUrl tempurl = QUrl(m_url); if (tempurl.scheme() == "http") { resetFaviconDownload(); - MessageBox::warning(this, tr("Error"), tr("Unable to fetch favicon.")); + MessageBox::warning(this, tr("Error"), tr("Unable to fetch favicon.") + "\n" + tr("Hint: You can enable Google as a fallback under Tools>Settings>Security")); } else { tempurl.setScheme("http"); m_url = tempurl.url(); @@ -243,7 +243,9 @@ void EditWidgetIcons::fetchFaviconFromGoogle(const QString& domain) if (config()->get("security/IconDownloadFallbackToGoogle", false).toBool() && m_fallbackToGoogle) { resetFaviconDownload(); m_fallbackToGoogle = false; - fetchFavicon(QUrl("https://www.google.com/s2/favicons?domain=" + domain)); + QUrl faviconUrl = QUrl("https://www.google.com/s2/favicons"); + faviconUrl.setQuery("domain=" + domain); + fetchFavicon(faviconUrl); } else { resetFaviconDownload(); MessageBox::warning(this, tr("Error"), tr("Unable to fetch favicon."));