check if url is valid

This commit is contained in:
thez3ro 2017-07-13 23:10:15 +02:00 committed by Janek Bevendorff
parent a888de19cd
commit 691e60d72b
2 changed files with 17 additions and 13 deletions

View File

@ -795,22 +795,24 @@ QString Entry::resolvePlaceholder(const QString& str) const
QString Entry::resolveUrl(const QString& url) const QString Entry::resolveUrl(const QString& url) const
{ {
#ifdef WITH_XC_HTTP #ifdef WITH_XC_HTTP
QString newurl = url; QString newUrl = url;
if (!url.contains("://")) { if (!url.contains("://")) {
// URL doesn't have a protocol, add https by default // 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") { if (tempUrl.isValid()) {
// URL is a cmd, hopefully the second argument is an URL if (tempUrl.scheme() == "cmd") {
QStringList cmd = newurl.split(" "); // URL is a cmd, hopefully the second argument is an URL
if (cmd.size() > 1) { QStringList cmd = newUrl.split(" ");
return resolveUrl(cmd[1].remove("'").remove("\"")); 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 #else
Q_UNUSED(url); Q_UNUSED(url);

View File

@ -226,7 +226,7 @@ void EditWidgetIcons::fetchFavicon(const QUrl& url)
QUrl tempurl = QUrl(m_url); QUrl tempurl = QUrl(m_url);
if (tempurl.scheme() == "http") { if (tempurl.scheme() == "http") {
resetFaviconDownload(); 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 { } else {
tempurl.setScheme("http"); tempurl.setScheme("http");
m_url = tempurl.url(); m_url = tempurl.url();
@ -243,7 +243,9 @@ void EditWidgetIcons::fetchFaviconFromGoogle(const QString& domain)
if (config()->get("security/IconDownloadFallbackToGoogle", false).toBool() && m_fallbackToGoogle) { if (config()->get("security/IconDownloadFallbackToGoogle", false).toBool() && m_fallbackToGoogle) {
resetFaviconDownload(); resetFaviconDownload();
m_fallbackToGoogle = false; 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 { } else {
resetFaviconDownload(); resetFaviconDownload();
MessageBox::warning(this, tr("Error"), tr("Unable to fetch favicon.")); MessageBox::warning(this, tr("Error"), tr("Unable to fetch favicon."));