Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for 'Remove All entries from this domain' on history item #1605

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/core/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'+1' at the end because:

  • in case lastIndexOf does not find a dot, it will return -1, adding 1 will set the domainStartIdx to 0
  • in case lastIndexOf does find a dot, it should return the idx after the dot

ie.
220.ro -> lastIndexOf returns -1, we add 1, domainStartIdx = 0, return value = 220.ro
vid.220.ro -> lastIndexOf returns 3, we add 1, domainStartIdx = 4, return value = 220.ro


return host.mid(domainStartIdx);
}

QString formatElapsedTime(int value)
{
if (value < 0)
Expand Down
1 change: 1 addition & 0 deletions src/core/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ QString elideText(const QString &text, const QFontMetrics &fontMetrics, QWidget
QString substitutePlaceholders(QString text, const QHash<QString, QString> &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);
Expand Down
9 changes: 7 additions & 2 deletions src/modules/windows/history/HistoryContentsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<quint64> entries;

for (int i = 0; i < m_model->rowCount(); ++i)
Expand All @@ -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());
}
Expand Down