Skip to content

Ignore trailing slashes when comparing place URLs

Wolfgang Müller requested to merge wylfen/dolphin:places-trailing-slash into master

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 681d8bb6 (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.


This is very close to what KIO does in KFilePlacesView::setUrl just with the additional normalization of the place's URL.

If wanted I can also send a merge request to KIO (since this same bug is happening there, too). That would fix the Places panel in Dolphin.

Merge request reports

Loading