After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 779182 - xdg-open fails with gio open for some uris
xdg-open fails with gio open for some uris
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
2.54.x
Other Linux
: Normal normal
: 2.56
Assigned To: gtkdev
gtkdev
: 773022 790664 793014 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2017-02-24 14:58 UTC by Ondrej Holy
Modified: 2018-02-08 08:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gio-tool: Do not alter uris before use (2.15 KB, patch)
2017-02-24 14:59 UTC, Ondrej Holy
none Details | Review
Fixes gio open for non-file paths (638 bytes, patch)
2017-10-29 01:15 UTC, asgerdrewsen
rejected Details | Review
gio-tool: Do not alter uris before use (2.71 KB, patch)
2017-11-06 10:44 UTC, Ondrej Holy
committed Details | Review

Description Ondrej Holy 2017-02-24 14:58:16 UTC
See:
https://bugzilla.redhat.com/show_bug.cgi?id=1426299
Comment 1 Ondrej Holy 2017-02-24 14:59:43 UTC
Created attachment 346646 [details] [review]
gio-tool: Do not alter uris before use

Uris may be altered by the following code, which breaks xdg-open:
file = g_file_new_for_commandline_arg (arg[i])
uri = g_file_get_uri (file);

Examples of possible uri changes:
mailto:email -> mailto:///email
magnet:?xt=urn:hash -> magnet:///?xt=urn:hash
ssh://user@host -> sftp://user@host

This patch causes that uris aren't preprocessed for locations with
scheme, however absolute and relative paths are still preprocessed.
Comment 2 Ondrej Holy 2017-02-24 15:04:32 UTC
It may be also fixed another way, please see the original gvfs-open bug report:
https://bugzilla.gnome.org/show_bug.cgi?id=738690#c8
Comment 3 Philip Withnall 2017-02-27 08:43:43 UTC
Looks to me like GIO should be fixed to not produce invalid URIs. afaik, “mailto:///email” is not valid (https://tools.ietf.org/html/rfc6068#section-2). It should be fine for g_file_get_uri() to produce a different URI from what was passed in to g_file_new_for_commandline_arg(), since it can canonicalise the URI. But what’s produced must be valid.
Comment 4 Ondrej Holy 2017-02-27 09:52:54 UTC
We can probably add some exceptions in URI generator e.g. for mailto, however, AFAIK e.g. magnet is not standardized and hard to say, what all other schemes are also affected...

So it would be probably better to not touch unknown schemes at all. See Attachment 302563 [details]. It should solve mailto, magnet... but not sure we don't break anything else with that patch.

However, it doesn't solve the problem with SSH -> SFTP. It is caused because SSH is handled like an alias for SFTP:
https://git.gnome.org/browse/gvfs/tree/daemon/sftp.mount.in#n6

We can probably remove this alias and provide separate mount file with SSH scheme, but AFAIK this is because we want to avoid duplicated mounts like sftp://localhost/ and ssh://localhost/. 

So not sure what is the best solution here. Alex?
Comment 5 Ondrej Holy 2017-02-27 09:58:16 UTC
Just a note that we should fix this for 3.24, because gvfs-open is redirected to "gio open" since 3.23, so xdg-open can't be used with gvfs-open as a workaround...
Comment 6 Matthias Clasen 2017-02-27 13:46:37 UTC
Urls get modified because of some round-tripping through GFile that is happening somewhere. That is a known, long-standing issue.

That being said, the xdg-open shell script should just be avoided.
Comment 7 Ondrej Holy 2017-03-07 10:32:02 UTC
*** Bug 773022 has been marked as a duplicate of this bug. ***
Comment 8 Alexander Larsson 2017-04-19 14:35:47 UTC
GFile uris are for uris that follow rfc 2396, not generic URIs, which have no particular structure other than at a very high level. There is not way we can parse e.g. mailto uris as GFiles and return them back unmodified, as we expect GFiles to have path-like semantics.

Not touching the uri:s like in the patch seems to be right here, and its something we do in other cases. In fact, its why g_app_info_launch_default_for_uri was added i believe.

I dunno what to do about the sftp alias issue though.
Comment 9 Pat Suwalski 2017-10-26 14:31:07 UTC
I big "+1" for a fix for this, or more information about exactly where the breakage is so that I may attempt a patch.

My usecase is that it breaks my KeePassX ssh:// URL opening, which I have launching an SSH session in a terminal. Needless to say, with this broken, my daily workflow with many dozens of hosts is impeded.

Here is the console output from KeePassX (yes, Qt still calls xdg-open):

---
This tool has been deprecated, use 'gio open' instead.
See 'gio help open' for more info.

gio: sftp://root@172.17.0.17/: The specified location is not mounted
---

I might be able to create a wrapper for xdg-open further up the path that avoids gio altogether, but that's obviously not a general solution.

As a fix, I'm not sure why GIO or any other component is ever altering a URI. I can imagine that a string should be decomposed and it tries to parse what the protocol is, host, user, whatever, but it should never take it apart and put it back together when I'm trying to launch a mime- or url-handler.
Comment 10 Pat Suwalski 2017-10-26 15:01:43 UTC
A temporary workaround was, in fact, to remove the ssh alias in sftp.mount, restart the gvfs backend, and alter my SSH launch script to strip the trailing slash.

Clearly, any real solution to this issue should address that a user's x-scheme-handler should override gvfs' opinion of mount points. They are logically different applications.
Comment 11 asgerdrewsen 2017-10-29 01:15:26 UTC
Created attachment 362472 [details] [review]
Fixes gio open for non-file paths

I've applied this patch which fixes this bug for me.
Comment 12 Philip Withnall 2017-11-03 13:18:06 UTC
Ondrej, has there been any progress on this elsewhere in GIO/GVFS, or is the status of things here still correct? It would be good to get this fixed.
Comment 13 Philip Withnall 2017-11-03 13:19:24 UTC
Review of attachment 362472 [details] [review]:

This looks very similar to attachment #346646 [details].
Comment 14 Ondrej Holy 2017-11-06 07:30:57 UTC
Yes, no progress on other places, the issue is still valid and attachment 346646 [details] [review] should fully fix that.
Comment 15 asgerdrewsen 2017-11-06 09:33:31 UTC
Using the patch from attachment 346646 [details] [review] doesn't work as you get the following error when compiling:

    ../glib/gio/gio-tool-open.c: In function ‘handle_open’:
    ../glib/gio/gio-tool-open.c:102:29: error: ‘file’ undeclared (first use in this function); did you mean ‘nice’?
               print_file_error (file, error->message);

This is due to the `file` variable declaration being moved inside the new if-statement.
Comment 16 Ondrej Holy 2017-11-06 10:44:07 UTC
Created attachment 363051 [details] [review]
gio-tool: Do not alter uris before use

Uris may be altered by the following code, which breaks xdg-open:
file = g_file_new_for_commandline_arg (arg[i])
uri = g_file_get_uri (file);

Examples of possible uri changes:
mailto:email -> mailto:///email
magnet:?xt=urn:hash -> magnet:///?xt=urn:hash
ssh://user@host -> sftp://user@host

This patch causes that uris aren't preprocessed for locations with
scheme, however absolute and relative paths are still preprocessed.
Comment 17 Ondrej Holy 2017-11-06 10:44:51 UTC
Fixed Comment 15 and rebased to master.
Comment 18 Philip Withnall 2017-11-07 11:29:02 UTC
Review of attachment 363051 [details] [review]:

OK, let’s go with this. Thanks Ondrej.
Comment 19 Ondrej Holy 2017-11-07 13:24:31 UTC
Attachment 363051 [details] pushed as 796599a - gio-tool: Do not alter uris before use
Comment 20 Ondrej Holy 2017-11-07 13:33:05 UTC
Pushed to glib-2-54 as well.
Comment 21 Sebastien Bacher 2017-11-21 14:04:09 UTC
*** Bug 790664 has been marked as a duplicate of this bug. ***
Comment 22 Ondrej Holy 2018-01-30 07:18:07 UTC
*** Bug 793014 has been marked as a duplicate of this bug. ***