From 011b8f9bf659e81166a9798972723c58526cb97f Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Wed, 18 Sep 2024 19:27:09 +0200 Subject: desktop-plasma: Patch place URL comparison in kde-apps/dolphin See also the merge request upstream [1] [1] https://invent.kde.org/system/dolphin/-/merge_requests/831 --- ...railing-slashes-when-comparing-place-URLs.patch | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 desktop-plasma/patches/kde-apps/dolphin/0001-Ignore-trailing-slashes-when-comparing-place-URLs.patch diff --git a/desktop-plasma/patches/kde-apps/dolphin/0001-Ignore-trailing-slashes-when-comparing-place-URLs.patch b/desktop-plasma/patches/kde-apps/dolphin/0001-Ignore-trailing-slashes-when-comparing-place-URLs.patch new file mode 100644 index 0000000..f950cc0 --- /dev/null +++ b/desktop-plasma/patches/kde-apps/dolphin/0001-Ignore-trailing-slashes-when-comparing-place-URLs.patch @@ -0,0 +1,75 @@ +From 4ff2cd4d5860b8db8c2cf4f054124d1bdc24f412 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Wolfgang=20M=C3=BCller?= +Date: Wed, 18 Sep 2024 18:06:06 +0200 +Subject: [PATCH] Ignore trailing slashes when comparing place URLs + +There's two locations where place URLs are compared in Dolphin. One +is in DolphinContextMenu::placeExists, which determines whether or not +to show an "Add to Places" context menu entry. The other one is in +DolphinViewContainer::caption, which provides the place name for use in +the window title, if applicable. + +Neither of these functions correctly normalize the URL to account for +trailing slashes. Whilst placeExists() does not even attempt it, +caption() was changed in 681d8bb6c (Fix wrong window titles, 2019-09-15) +to support this using a regular expression. + +However, caption() fails to escape the URL before incorporating it in +the regular expression, leading to failed matches and errors like the +following when browsing to directories that do not happen to make up a +valid regular expression: + + QString(View)::contains(): called on an invalid QRegularExpression + object (pattern is '\A(?:file:///home/foo/[Z-A]/?)\z') + +Instead of relying on complex and possibly brittle regular expressions, +use KFilePlacesModel's closestItem() function to find the closest +matching URL and then finally check whether the normalized URLs match +exactly. +--- + src/dolphincontextmenu.cpp | 5 +++-- + src/dolphinviewcontainer.cpp | 10 +++++----- + 2 files changed, 8 insertions(+), 7 deletions(-) + +diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp +index 68f6dbd21..8f418aed5 100644 +--- a/src/dolphincontextmenu.cpp ++++ b/src/dolphincontextmenu.cpp +@@ -381,9 +381,10 @@ bool DolphinContextMenu::placeExists(const QUrl &url) const + { + const KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel(); + +- const auto &matchedPlaces = placesModel->match(placesModel->index(0, 0), KFilePlacesModel::UrlRole, url, 1, Qt::MatchExactly); ++ QUrl stripped_url = url.adjusted(QUrl::StripTrailingSlash); ++ QModelIndex url_index = placesModel->closestItem(stripped_url); + +- return !matchedPlaces.isEmpty(); ++ return url_index.isValid() && placesModel->url(url_index).adjusted(QUrl::StripTrailingSlash) == stripped_url; + } + + QAction *DolphinContextMenu::createPasteAction() +diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp +index ef76042b8..a74770fb5 100644 +--- a/src/dolphinviewcontainer.cpp ++++ b/src/dolphinviewcontainer.cpp +@@ -552,12 +552,12 @@ QString DolphinViewContainer::caption() const + } + + KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel(); +- const QString pattern = url().adjusted(QUrl::StripTrailingSlash).toString(QUrl::FullyEncoded).append("/?"); +- const auto &matchedPlaces = +- placesModel->match(placesModel->index(0, 0), KFilePlacesModel::UrlRole, QRegularExpression::anchoredPattern(pattern), 1, Qt::MatchRegularExpression); + +- if (!matchedPlaces.isEmpty()) { +- return placesModel->text(matchedPlaces.first()); ++ QUrl stripped_url = url().adjusted(QUrl::StripTrailingSlash); ++ QModelIndex url_index = placesModel->closestItem(stripped_url); ++ ++ if (url_index.isValid() && placesModel->url(url_index).adjusted(QUrl::StripTrailingSlash) == stripped_url) { ++ return placesModel->text(url_index); + } + + if (!url().isLocalFile()) { +-- +2.46.0 + -- cgit v1.2.3-2-gb3c3