diff options
author | Brendan Taylor <whateley@gmail.com> | 2011-11-28 20:51:56 -0700 |
---|---|---|
committer | Brendan Taylor <whateley@gmail.com> | 2011-11-28 20:51:56 -0700 |
commit | b4bf5fa304f374680892174575aa01d7bcc94c1e (patch) | |
tree | 5dfa280f0bda433df72b808c6a98f216797942db | |
parent | 83c4ba38435b494e5fda968b83d1dc1d145eea3b (diff) |
don't segfault when toggling a nonexistent variable
-rw-r--r-- | src/commands.c | 5 | ||||
-rw-r--r-- | tests/test-command.c | 6 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/commands.c b/src/commands.c index 708ed49..2e60233 100644 --- a/src/commands.c +++ b/src/commands.c @@ -177,6 +177,11 @@ toggle_var(WebKitWebView *page, GArray *argv, GString *result) { uzbl_cmdprop *c = get_var_c(var_name); + if(!c) { + set_var_value(var_name, argv_idx(argv, 1)); + return; + } + switch(c->type) { case TYPE_STR: { diff --git a/tests/test-command.c b/tests/test-command.c index b3c3d0c..2d91b64 100644 --- a/tests/test-command.c +++ b/tests/test-command.c @@ -351,6 +351,12 @@ test_toggle_string (void) { // and wrap to the first value when it reaches the end. parse_cmd_line("toggle useragent 'x' 'y'", NULL); g_assert_cmpstr("x", ==, uzbl.net.useragent); + + // user-defined variables can be toggled too. + parse_cmd_line("toggle new_variable 'x' 'y'", NULL); + gchar *value = get_var_value_string("new_variable"); + g_assert_cmpstr("x", ==, value); + g_free(value); } int |