Skip to content

Commit

Permalink
Add check to scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
varjolintu committed May 28, 2018
1 parent 36b7601 commit b1701f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
30 changes: 17 additions & 13 deletions src/browser/BrowserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void BrowserService::updateEntry(const QString& id, const QString& uuid, const Q
}
}

QList<Entry*> BrowserService::searchEntries(Database* db, const QString& hostname, const int port)
QList<Entry*> BrowserService::searchEntries(Database* db, const QString& hostname, const QString& url)
{
QList<Entry*> entries;
Group* rootGroup = db->rootGroup();
Expand All @@ -375,20 +375,25 @@ QList<Entry*> BrowserService::searchEntries(Database* db, const QString& hostnam
}

for (Entry* entry : EntrySearcher().search(hostname, rootGroup, Qt::CaseInsensitive)) {
QString title = entry->title();
QString url = entry->url();

// Ignore entry if port defined in the URL doesn't match
const int entryPort = QUrl(url).port();
if (entryPort > 0 && entryPort != port) {
QString entryTitle = entry->title();
QString entryUrl = entry->url();
QUrl entryQUrl(entryUrl);
QString entryScheme = entryQUrl.scheme();
int entryPort = entryQUrl.port();
QUrl qUrl(url);
QString scheme = qUrl.scheme();
int port = qUrl.port();

// Ignore entry if port or scheme defined in the URL doesn't match
if ((entryPort > 0 && entryPort != port) || entryScheme.compare(scheme) != 0) {
continue;
}

// Filter to match hostname in Title and Url fields
if ((!title.isEmpty() && hostname.contains(title))
|| (!url.isEmpty() && hostname.contains(url))
|| (matchUrlScheme(title) && hostname.endsWith(QUrl(title).host()))
|| (matchUrlScheme(url) && hostname.endsWith(QUrl(url).host())) ) {
if ((!entryTitle.isEmpty() && hostname.contains(entryTitle))
|| (!entryUrl.isEmpty() && hostname.contains(entryUrl))
|| (matchUrlScheme(entryTitle) && hostname.endsWith(QUrl(entryTitle).host()))
|| (matchUrlScheme(entryUrl) && hostname.endsWith(QUrl(entryUrl).host())) ) {
entries.append(entry);
}
}
Expand Down Expand Up @@ -424,11 +429,10 @@ QList<Entry*> BrowserService::searchEntries(const QString& url, const StringPair

// Search entries matching the hostname
QString hostname = QUrl(url).host();
int port = QUrl(url).port();
QList<Entry*> entries;
do {
for (Database* db : databases) {
entries << searchEntries(db, hostname, port);
entries << searchEntries(db, hostname, url);
}
} while (entries.isEmpty() && removeFirstDomain(hostname));

Expand Down
2 changes: 1 addition & 1 deletion src/browser/BrowserService.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BrowserService : public QObject
Entry* getConfigEntry(bool create = false);
QString getKey(const QString& id);
void addEntry(const QString& id, const QString& login, const QString& password, const QString& url, const QString& submitUrl, const QString& realm);
QList<Entry*> searchEntries(Database* db, const QString& hostname, const int port);
QList<Entry*> searchEntries(Database* db, const QString& hostname, const QString& url);
QList<Entry*> searchEntries(const QString& url, const StringPairList& keyList);
void removeSharedEncryptionKeys();
void removeStoredPermissions();
Expand Down

0 comments on commit b1701f6

Please sign in to comment.