summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWolfgang Müller2024-09-18 19:27:09 +0200
committerWolfgang Müller2024-09-18 19:27:09 +0200
commit011b8f9bf659e81166a9798972723c58526cb97f (patch)
tree9312db0f156e2d8d8f0142613c3e26147db881ef
parent91b59e1fe5a35f405c9e692d221dc29aca68a599 (diff)
downloadportage-roles-011b8f9bf659e81166a9798972723c58526cb97f.tar.gz
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
Diffstat (limited to '')
-rw-r--r--desktop-plasma/patches/kde-apps/dolphin/0001-Ignore-trailing-slashes-when-comparing-place-URLs.patch75
1 files changed, 75 insertions, 0 deletions
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?= <wolf@oriole.systems>
+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
+