]> cloud.milkyroute.net Git - dolphin.git/commit
Ignore trailing slashes when comparing place URLs
authorWolfgang Müller <wolf@oriole.systems>
Thu, 19 Sep 2024 09:46:09 +0000 (11:46 +0200)
committerWolfgang Müller <wolf@oriole.systems>
Thu, 19 Sep 2024 09:46:09 +0000 (11:46 +0200)
commit046ddcf5607e597cd6290147bf7ee10c08e526dd
treeca1c1f2509ee9f9e8ded9d922e082d45c7c87926
parent5c069471fccc41051b967be69f95655b3e0b73ef
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
src/dolphinviewcontainer.cpp