Pass URLs to browser as a single argument
Parsing the arguments with g_shell_parse_argv is more safe than just splitting it by spaces. Also this allows to pass values with spaces to the browser command.
This commit is contained in:
parent
851953f5ef
commit
357c4309e6
18
src/menu.c
18
src/menu.c
@ -102,6 +102,11 @@ char *extract_urls(const char *to_match)
|
|||||||
*/
|
*/
|
||||||
void open_browser(const char *in)
|
void open_browser(const char *in)
|
||||||
{
|
{
|
||||||
|
if (!settings.browser_cmd) {
|
||||||
|
LOG_C("Unable to open browser: No browser command set.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
char *url = NULL;
|
char *url = NULL;
|
||||||
|
|
||||||
// If any, remove leading [ linktext ] from URL
|
// If any, remove leading [ linktext ] from URL
|
||||||
@ -122,9 +127,16 @@ void open_browser(const char *in)
|
|||||||
if (browser_pid2) {
|
if (browser_pid2) {
|
||||||
exit(0);
|
exit(0);
|
||||||
} else {
|
} else {
|
||||||
char *browser_cmd = g_strconcat(settings.browser, " ", url, NULL);
|
int argc = 2+g_strv_length(settings.browser_cmd);
|
||||||
char **cmd = g_strsplit(browser_cmd, " ", 0);
|
char **argv = g_malloc_n(argc, sizeof(char*));
|
||||||
execvp(cmd[0], cmd);
|
|
||||||
|
memcpy(argv, settings.browser_cmd, argc * sizeof(char*));
|
||||||
|
argv[argc-2] = url;
|
||||||
|
argv[argc-1] = NULL;
|
||||||
|
|
||||||
|
execvp(argv[0], argv);
|
||||||
|
g_free(argv);
|
||||||
|
|
||||||
// execvp won't return if it's successful
|
// execvp won't return if it's successful
|
||||||
// so, if we're here, it's definitely an error
|
// so, if we're here, it's definitely an error
|
||||||
fprintf(stderr, "Warning: failed to execute '%s': %s\n",
|
fprintf(stderr, "Warning: failed to execute '%s': %s\n",
|
||||||
|
@ -448,6 +448,16 @@ void load_settings(char *cmdline_config_path)
|
|||||||
"path to browser"
|
"path to browser"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
{
|
||||||
|
GError *error = NULL;
|
||||||
|
if (!g_shell_parse_argv(settings.browser, NULL, &settings.browser_cmd, &error)) {
|
||||||
|
LOG_W("Unable to parse browser command: '%s'."
|
||||||
|
" URL functionality will be disabled.", error->message);
|
||||||
|
g_error_free(error);
|
||||||
|
settings.browser_cmd = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
char *c = option_get_string(
|
char *c = option_get_string(
|
||||||
"global",
|
"global",
|
||||||
|
@ -75,6 +75,7 @@ struct settings {
|
|||||||
char *dmenu;
|
char *dmenu;
|
||||||
char **dmenu_cmd;
|
char **dmenu_cmd;
|
||||||
char *browser;
|
char *browser;
|
||||||
|
char **browser_cmd;
|
||||||
enum icon_position icon_position;
|
enum icon_position icon_position;
|
||||||
int max_icon_size;
|
int max_icon_size;
|
||||||
char *icon_path;
|
char *icon_path;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user