Permalink
Browse files

don't segfault when toggling a nonexistent variable

  • Loading branch information...
1 parent 83c4ba3 commit b4bf5fa304f374680892174575aa01d7bcc94c1e @bct bct committed Nov 29, 2011
Showing with 11 additions and 0 deletions.
  1. +5 −0 src/commands.c
  2. +6 −0 tests/test-command.c
View
@@ -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:
{
@@ -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

0 comments on commit b4bf5fa

Please sign in to comment.