Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell/ev-window.c
diff options
context:
space:
mode:
authorCarlos Garcia Campos <carlosgc@gnome.org>2009-12-20 17:26:27 (GMT)
committer Carlos Garcia Campos <carlosgc@gnome.org>2009-12-20 17:32:08 (GMT)
commit4703212e1b44d4d385dc894cfbdc037db6e2112b (patch)
tree7411f7df3f7396d4d050f28b1d1c9fbfff397835 /shell/ev-window.c
parentbf8fe0d26b7319b9ad3a8a79fbf618343f603c62 (diff)
Do not fail to open external uri links that are relative paths
If an external uri is not a valid uri (it doesn't contain :// nor mailto:) we assume it's http if it starts with www, otherwise we build a new uri for the relative path with the document uri as base. Fixes bgo#604716.
Diffstat (limited to 'shell/ev-window.c')
-rw-r--r--shell/ev-window.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 11e3c12..95c2191 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -5594,18 +5594,35 @@ launch_external_uri (EvWindow *window, EvLinkAction *action)
if (!g_strstr_len (uri, strlen (uri), "://") &&
!g_str_has_prefix (uri, "mailto:")) {
- gchar *http;
-
- /* Not a valid uri, assuming it's http */
- http = g_strdup_printf ("http://%s", uri);
- ret = g_app_info_launch_default_for_uri (http, context, &error);
- g_free (http);
+ gchar *new_uri;
+
+ /* Not a valid uri, assume http if it starts with www */
+ if (g_str_has_prefix (uri, "www.")) {
+ new_uri = g_strdup_printf ("http://%s", uri);
+ } else {
+ GFile *file, *parent;
+
+ file = g_file_new_for_uri (window->priv->uri);
+ parent = g_file_get_parent (file);
+ g_object_unref (file);
+ if (parent) {
+ gchar *parent_uri = g_file_get_uri (parent);
+
+ new_uri = g_build_filename (parent_uri, uri, NULL);
+ g_free (parent_uri);
+ g_object_unref (parent);
+ } else {
+ new_uri = g_strdup_printf ("file:///%s", uri);
+ }
+ }
+ ret = g_app_info_launch_default_for_uri (new_uri, context, &error);
+ g_free (new_uri);
} else {
ret = g_app_info_launch_default_for_uri (uri, context, &error);
}
-
+
if (ret == FALSE) {
- ev_window_error_message (window, error,
+ ev_window_error_message (window, error,
"%s", _("Unable to open external link"));
g_error_free (error);
}