diff --git a/shell/ev-application.c b/shell/ev-application.c index 9c01996e..029520fb 100644 --- a/shell/ev-application.c +++ b/shell/ev-application.c @@ -215,6 +215,27 @@ ev_display_open_if_needed (const gchar *name) } #endif /* ENABLE_DBUS */ +/* + * g_app_info_create_from_commandline() expands desktop entry field codes + * (%f, %u, ...) before splitting the arguments, even inside quotes, so "%" + * must be escaped for the value to reach the new instance unchanged. + */ +static gchar * +ev_spawn_quote_argument (const gchar *arg) +{ + gchar *quoted; + gchar **parts; + gchar *escaped; + + quoted = g_shell_quote (arg); + parts = g_strsplit (quoted, "%", -1); + escaped = g_strjoinv ("%%", parts); + g_strfreev (parts); + g_free (quoted); + + return escaped; +} + static void ev_spawn (const char *uri, GdkScreen *screen, @@ -238,7 +259,7 @@ ev_spawn (const char *uri, if (dest) { switch (ev_link_dest_get_dest_type (dest)) { case EV_LINK_DEST_TYPE_PAGE_LABEL: { - gchar *quoted = g_shell_quote (ev_link_dest_get_page_label (dest)); + gchar *quoted = ev_spawn_quote_argument (ev_link_dest_get_page_label (dest)); g_string_append_printf (cmd, " --page-label=%s", quoted); g_free (quoted); break; @@ -248,7 +269,7 @@ ev_spawn (const char *uri, ev_link_dest_get_page (dest) + 1); break; case EV_LINK_DEST_TYPE_NAMED: { - gchar *quoted = g_shell_quote (ev_link_dest_get_named_dest (dest)); + gchar *quoted = ev_spawn_quote_argument (ev_link_dest_get_named_dest (dest)); g_string_append_printf (cmd, " --named-dest=%s", quoted); g_free (quoted); break; @@ -260,7 +281,7 @@ ev_spawn (const char *uri, /* Find string */ if (search_string) { - gchar *quoted = g_shell_quote (search_string); + gchar *quoted = ev_spawn_quote_argument (search_string); g_string_append_printf (cmd, " --find=%s", quoted); g_free (quoted); }