From 35c6df2535c784bd4e0aaa91606b7bcbb5afa67c Mon Sep 17 00:00:00 2001 From: thez3ro Date: Thu, 29 Jun 2017 19:54:49 +0200 Subject: [PATCH] resolve URL for correct favicon downloading, fixes #240 #238 --- src/core/Entry.cpp | 25 +++++++++++++++++++++++++ src/core/Entry.h | 2 ++ src/gui/EditWidgetIcons.cpp | 11 +++++++++-- src/gui/entry/EditEntryWidget.cpp | 2 +- src/http/Service.cpp | 2 +- tests/CMakeLists.txt | 2 +- 6 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index a8cc6d3b..831661e7 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -237,6 +237,11 @@ QString Entry::url() const return m_attributes->value(EntryAttributes::URLKey); } +QString Entry::webUrl() const +{ + return resolveUrl(m_attributes->value(EntryAttributes::URLKey)); +} + QString Entry::username() const { return m_attributes->value(EntryAttributes::UserNameKey); @@ -784,3 +789,23 @@ QString Entry::resolvePlaceholder(const QString& str) const return result; } + +QString Entry::resolveUrl(const QString& url) const +{ + QString newurl = url; + if (!url.contains("://")) { + // URL doesn't have a protocol, add https by default + newurl.prepend("https://"); + } + QUrl uurl = QUrl(newurl); + + if(uurl.scheme() == "cmd") { + // URL is a cmd, hopefully the second argument it's an URL + QStringList cmd = newurl.split(" "); + return resolveUrl(cmd[1].remove("'").remove("\"")); + } else if(uurl.scheme() != "http" && uurl.scheme() != "https") { + // URL isn't very nice + return QString(""); + } + return uurl.url(); +} \ No newline at end of file diff --git a/src/core/Entry.h b/src/core/Entry.h index 91a0012a..889a9334 100644 --- a/src/core/Entry.h +++ b/src/core/Entry.h @@ -78,6 +78,7 @@ public: const AutoTypeAssociations* autoTypeAssociations() const; QString title() const; QString url() const; + QString webUrl() const; QString username() const; QString password() const; QString notes() const; @@ -143,6 +144,7 @@ public: void copyDataFrom(const Entry* other); QString resolveMultiplePlaceholders(const QString& str) const; QString resolvePlaceholder(const QString& str) const; + QString resolveUrl(const QString& url) const; /** * Call before and after set*() methods to create a history item diff --git a/src/gui/EditWidgetIcons.cpp b/src/gui/EditWidgetIcons.cpp index 42bc507d..e2c75c96 100644 --- a/src/gui/EditWidgetIcons.cpp +++ b/src/gui/EditWidgetIcons.cpp @@ -223,8 +223,15 @@ void EditWidgetIcons::fetchFavicon(const QUrl& url) } m_httpClient->setConnectingTimeOut(5000, [this]() { - resetFaviconDownload(); - MessageBox::warning(this, tr("Error"), tr("Unable to fetch favicon.")); + QUrl tempurl = QUrl(m_url); + if (tempurl.scheme() == "http") { + resetFaviconDownload(); + MessageBox::warning(this, tr("Error"), tr("Unable to fetch favicon.")); + } else { + tempurl.setScheme("http"); + tempurl.setPath("/favicon.ico"); + fetchFavicon(tempurl); + } }); m_ui->faviconButton->setDisabled(true); diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index 2561564c..bea10b99 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -363,7 +363,7 @@ void EditEntryWidget::setForms(const Entry* entry, bool restore) IconStruct iconStruct; iconStruct.uuid = entry->iconUuid(); iconStruct.number = entry->iconNumber(); - m_iconsWidget->load(entry->uuid(), m_database, iconStruct, entry->url()); + m_iconsWidget->load(entry->uuid(), m_database, iconStruct, entry->webUrl()); connect(m_mainUi->urlEdit, SIGNAL(textChanged(QString)), m_iconsWidget, SLOT(setUrl(QString))); m_autoTypeUi->enableButton->setChecked(entry->autoTypeEnabled()); diff --git a/src/http/Service.cpp b/src/http/Service.cpp index 639898da..768a5774 100644 --- a/src/http/Service.cpp +++ b/src/http/Service.cpp @@ -203,7 +203,7 @@ QList Service::searchEntries(Database* db, const QString& hostname) const auto results = EntrySearcher().search(hostname, rootGroup, Qt::CaseInsensitive); for (Entry* entry: results) { QString title = entry->title(); - QString url = entry->url(); + QString url = entry->webUrl(); //Filter to match hostname in Title and Url fields if ( (!title.isEmpty() && hostname.contains(title)) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 67661f55..2a420270 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -98,7 +98,7 @@ set(TEST_LIBRARIES set(testsupport_SOURCES modeltest.cpp FailDevice.cpp) add_library(testsupport STATIC ${testsupport_SOURCES}) -target_link_libraries(testsupport ${MHD_LIBRARIES} Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Test) +target_link_libraries(testsupport Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Test) if(YUBIKEY_FOUND) set(TEST_LIBRARIES ${TEST_LIBRARIES} ${YUBIKEY_LIBRARIES})