Bug 44163 - xdg-open fails on encountering a list for x-scheme-handler
Summary: xdg-open fails on encountering a list for x-scheme-handler
Alias: None
Product: Portland
Classification: Unclassified
Component: xdg-utils (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Portland Bugs
QA Contact:
Keywords: patch
Depends on:
Blocks: 101640
  Show dependency treegraph
Reported: 2011-12-26 20:02 UTC by Stephan Sokolow
Modified: 2017-11-29 20:02 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:

Possible fix (1.95 KB, patch)
2011-12-26 20:33 UTC, Stephan Sokolow
Details | Splinter Review
fix desktop-file-to-binary (2.20 KB, patch)
2016-06-03 07:18 UTC, simon
Details | Splinter Review
xdg-mime only return existing desktop files (1.15 KB, patch)
2016-06-03 07:26 UTC, simon
Details | Splinter Review
This patch checks filenames with a - after checking the vendor prefix. (2.30 KB, patch)
2016-11-09 23:52 UTC, Simon Lees (SUSE)
Details | Splinter Review
fix autotests (1.83 KB, patch)
2017-09-30 18:41 UTC, Nicholas Guriev
Details | Splinter Review

Description Stephan Sokolow 2011-12-26 20:02:52 UTC
According to Specifications/mime-actions-spec, an entry in mimeapps.list is supposed to be treated as a semicolon-separated list of applications, sorted from most to least preferred.

However, with current git HEAD (b961235b197647d6649ef3d48d7cc2cecafe3d47), xdg-open simply treats it as a filename and uses the $BROWSER fallback if xdg-mime returns a semicolon-separated list.
Comment 1 Stephan Sokolow 2011-12-26 20:33:15 UTC
Created attachment 54838 [details] [review]
Possible fix

Here's a patch that should solve the problem... but since I can't remember what I did to make xdg-open the last time, it has only been tested in the sense that:
 1. it worked for me when I wrote it in the generated xdg-open.
 2. When I asked diff to compare the `git diff` output for both cases, the only lines that didn't match were ones I didn't touch. (so I'm guessing make did)
Comment 2 Wolfgang Bauer 2016-05-13 09:52:05 UTC
I stumbled over the same problem when trying to reproduce a bug filed at openSUSE's bugzilla (https://bugzilla.opensuse.org/show_bug.cgi?id=979265), i.e. the same problem exists when trying to open a folder with xdg-open (e.g. "xdg-open ." as in this specific openSUSE bugreport).

I don't think patching xdg-open is the proper solution though.
IMHO, "xdg-mime query default xxx" should not return the ';' (or the whole line actually, including all listed applications) in the first place, it doesn't when run inside a KDE session.

To demonstrate the problem more clearly:
Say, mimeapps.list contains this:
[Default Applications]

Inside a KDE session "xdg-mime query default inode/directory" returns "krusader.desktop".
In IceWM e.g. (i.e. when the generic path is taken) it's "kde4-krusader.desktop;" instead, on which xdg-open chokes then.

The problem is even more obvious if you add a second application to the default applications line, as explicitly mentioned in the specification (https://specifications.freedesktop.org/mime-apps-spec/latest/ar01s04.html):
[Default Applications]

Inside KDE, xdg-mime still returns "krusader.desktop", but the generic version returns the whole line, "kde4-krusader.desktop;kde4-dolphin.desktop;"

Apparently the correct behavior would be to check the specified desktop files in the order specified and return only the first one that actually exists (this is how it behaves inside a KDE session).
But it would help already if it would just strip everything after (and including) the first semicolon I suppose.
Comment 3 Rex Dieter 2016-05-13 12:02:02 UTC
What version of xdg-utils are you using to test?

Using the latest code, slightly newer than recent 1.1.1 release, I cannot reproduce your findings (marking fixed)
Comment 4 Wolfgang Bauer 2016-05-14 01:04:26 UTC
(In reply to Rex Dieter from comment #3)
> What version of xdg-utils are you using to test?

Sorry, I forgot to specify that.

I used openSUSE's latest package from the devel repo, which contains a git snapshot from 20151219.
The most recent entry in the changelog is this:
2015-12-19 Rex Dieter <rdieter@fedoraproject.org>
   * xdg-open: improve fallbacks, add open_generic (almost) everywhere (BR93442)

I could try the latest git version too, but I don't see any change that should fix it since then...

Please note that this only happens when the generic code path is taken though, i.e. you need to run it in IceWM e.g. (not KDE or GNOME).
Comment 5 Rex Dieter 2016-05-16 13:19:48 UTC
I set env var:


prior to running xdg-utils tools, that should be sufficient for testing (as far as I can tell)
Comment 6 Wolfgang Bauer 2016-05-20 10:30:28 UTC
(In reply to Rex Dieter from comment #5)
> I set env var:
> prior to running xdg-utils tools, that should be sufficient for testing (as
> far as I can tell)

Yes, should be.

Still, the problem is not fixed here, also with latest git master:
:~> xdg-mime query default inode/directory
Checking /home/wolfi/.config/mimeapps.list

When running "xdg-open .", it starts Firefox instead.

/home/wolfi/.config/mimeapps.list looks like this:
[Added Associations]

[Default Applications]

Changing the last line (below "[Default Applications]") to just "inode/directory=kde4-krusader.desktop" (without a ';') makes it work as expected.

But, the openSUSE maintainer is working on a fix, see https://bugzilla.opensuse.org/show_bug.cgi?id=979265
Comment 7 Rex Dieter 2016-05-20 16:59:14 UTC
OK, seems my testing methodology was flawed, let's continue the investigation.
Comment 8 Rex Dieter 2016-05-20 17:14:20 UTC
here's the patch I'm currently testing (with good results so far):

diff --git a/scripts/xdg-mime.in b/scripts/xdg-mime.in
index 63b8a82..c60f220 100644
--- a/scripts/xdg-mime.in
+++ b/scripts/xdg-mime.in
@@ -370,7 +370,7 @@ check_mimeapps_list()
-' "$mimeapps_list")
+' "$mimeapps_list" | cut -d ';' -f 1)
             if [ -n "$result" ]; then
                 echo "$result"
Comment 10 simon 2016-06-03 07:18:56 UTC
Created attachment 124299 [details] [review]
fix desktop-file-to-binary

This patch is required to make my next patch work properly
Comment 11 simon 2016-06-03 07:26:18 UTC
Created attachment 124300 [details] [review]
xdg-mime only return existing desktop files

This fixes xdg-mime in a "more correct way" rather then returning the first item it returns the first item in the list that exists. For an item to exist its desktop file and binary must both be found. 

Its been a long time since i've contributed patches so I don't remember how to so feel free to point me to the doco on that.
Comment 12 Simon Lees (SUSE) 2016-11-09 23:52:23 UTC
Created attachment 127887 [details] [review]
This patch checks filenames with a - after checking the vendor prefix.
Comment 13 Simon Lees (SUSE) 2016-11-09 23:54:31 UTC
I'm going to re open this as the patches attached haven't been accepted and do a better job of this by only returning the result if the desktop file and binary actually exist on the system.
Comment 14 Rex Dieter 2017-02-28 15:04:16 UTC
applied patches  Thanks!   (sorry for the delay)

I'm still a little nervous about the behavior change, but I think it's for the best long-term.
Comment 15 Nicholas Guriev 2017-09-30 18:41:41 UTC
Created attachment 134577 [details] [review]
fix autotests

Please apply my patch to fix tests.
Comment 16 Rex Dieter 2017-11-29 20:02:54 UTC
latest patch applied, thanks.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.