diff --git a/src/core/Utils.cpp b/src/core/Utils.cpp index 437f8f2211..30d362f1ac 100644 --- a/src/core/Utils.cpp +++ b/src/core/Utils.cpp @@ -399,6 +399,30 @@ QString extractHost(const QUrl &url) return (url.isLocalFile() ? QLatin1String("localhost") : url.host()); } +QString extractDomainName(const QUrl &url) +{ + if (!url.isValid()) + { + return {}; + } + + const QString host = url.host(); + if (host.isEmpty()) + { + return {}; + } + + const QString tld = url.topLevelDomain(); + if (tld.isEmpty()) + { + return {}; + } + + const int domainStartIdx = host.lastIndexOf('.', (-1 * tld.size()) - 1) + 1; + + return host.mid(domainStartIdx); +} + QString formatElapsedTime(int value) { if (value < 0) diff --git a/src/core/Utils.h b/src/core/Utils.h index a03f2d9f3d..74ba80fb65 100644 --- a/src/core/Utils.h +++ b/src/core/Utils.h @@ -100,6 +100,7 @@ QString elideText(const QString &text, const QFontMetrics &fontMetrics, QWidget QString substitutePlaceholders(QString text, const QHash &placeholders); QString savePixmapAsDataUri(const QPixmap &pixmap); QString extractHost(const QUrl &url); +QString extractDomainName(const QUrl &url); QString formatElapsedTime(int value); QString formatDateTime(const QDateTime &dateTime, QString format = {}, bool allowFancy = true); QString formatUnit(qint64 value, bool isSpeed = false, int precision = 1, bool appendRaw = false); diff --git a/src/modules/windows/history/HistoryContentsWidget.cpp b/src/modules/windows/history/HistoryContentsWidget.cpp index 48b88c07a3..b5a3358530 100644 --- a/src/modules/windows/history/HistoryContentsWidget.cpp +++ b/src/modules/windows/history/HistoryContentsWidget.cpp @@ -187,7 +187,12 @@ void HistoryContentsWidget::removeDomainEntries() return; } - const QString host(QUrl(domainItem->text()).host()); + const QString domain(Utils::extractDomainName(QUrl(domainItem->text()))); + if (domain.isEmpty()) + { + return; + } + QVector entries; for (int i = 0; i < m_model->rowCount(); ++i) @@ -203,7 +208,7 @@ void HistoryContentsWidget::removeDomainEntries() { const QStandardItem *entryItem(groupItem->child(j, 0)); - if (entryItem && host == QUrl(entryItem->text()).host()) + if (entryItem && domain == Utils::extractDomainName(QUrl(entryItem->text()))) { entries.append(entryItem->data(IdentifierRole).toULongLong()); }