diff options
| -rw-r--r-- | lib/parse_ini.c | 5 | ||||
| -rw-r--r-- | lib/tests/plugin.ini | 5 | ||||
| -rw-r--r-- | lib/tests/test_ini.c | 12 |
3 files changed, 17 insertions, 5 deletions
diff --git a/lib/parse_ini.c b/lib/parse_ini.c index 38bcb39b..ade77e5f 100644 --- a/lib/parse_ini.c +++ b/lib/parse_ini.c | |||
| @@ -212,6 +212,7 @@ static int add_option(FILE *f, np_arg_list **optlst){ | |||
| 212 | else optend=NULL; | 212 | else optend=NULL; |
| 213 | } | 213 | } |
| 214 | if(optend==NULL) optend=eqptr; | 214 | if(optend==NULL) optend=eqptr; |
| 215 | //printf("o1: %c\n", *optptr[optend]); | ||
| 215 | --optend; | 216 | --optend; |
| 216 | /* ^[[:space:]]*=foo is a syntax error */ | 217 | /* ^[[:space:]]*=foo is a syntax error */ |
| 217 | if(optptr==eqptr) die(STATE_UNKNOWN, _("Config file error\n")); | 218 | if(optptr==eqptr) die(STATE_UNKNOWN, _("Config file error\n")); |
| @@ -242,6 +243,8 @@ static int add_option(FILE *f, np_arg_list **optlst){ | |||
| 242 | equals=1; | 243 | equals=1; |
| 243 | cfg_len+=1; | 244 | cfg_len+=1; |
| 244 | } | 245 | } |
| 246 | /* A line with no equal sign isn't valid */ | ||
| 247 | if(equals==0) die(STATE_UNKNOWN, _("Config file error\n")); | ||
| 245 | 248 | ||
| 246 | /* okay, now we have all the info we need, so we create a new np_arg_list | 249 | /* okay, now we have all the info we need, so we create a new np_arg_list |
| 247 | * element and set the argument... | 250 | * element and set the argument... |
| @@ -260,8 +263,8 @@ static int add_option(FILE *f, np_arg_list **optlst){ | |||
| 260 | read_pos+=2; | 263 | read_pos+=2; |
| 261 | } | 264 | } |
| 262 | strncpy(&optnew->arg[read_pos], optptr, opt_len); read_pos+=opt_len; | 265 | strncpy(&optnew->arg[read_pos], optptr, opt_len); read_pos+=opt_len; |
| 263 | if(equals) optnew->arg[read_pos++]='='; | ||
| 264 | if(value) { | 266 | if(value) { |
| 267 | optnew->arg[read_pos++]='='; | ||
| 265 | strncpy(&optnew->arg[read_pos], valptr, val_len); read_pos+=val_len; | 268 | strncpy(&optnew->arg[read_pos], valptr, val_len); read_pos+=val_len; |
| 266 | } | 269 | } |
| 267 | optnew->arg[read_pos]='\0'; | 270 | optnew->arg[read_pos]='\0'; |
diff --git a/lib/tests/plugin.ini b/lib/tests/plugin.ini index eb869c63..d07fc4f3 100644 --- a/lib/tests/plugin.ini +++ b/lib/tests/plugin.ini | |||
| @@ -7,4 +7,9 @@ password=secret # Remember to change later | |||
| 7 | u=admin | 7 | u=admin |
| 8 | p=secret | 8 | p=secret |
| 9 | 9 | ||
| 10 | [check space_and_flags] | ||
| 11 | foo=bar | ||
| 12 | a= | ||
| 13 | b= | ||
| 14 | bar= | ||
| 10 | 15 | ||
diff --git a/lib/tests/test_ini.c b/lib/tests/test_ini.c index de9f8adf..9031f7f8 100644 --- a/lib/tests/test_ini.c +++ b/lib/tests/test_ini.c | |||
| @@ -52,18 +52,18 @@ main (int argc, char **argv) | |||
| 52 | { | 52 | { |
| 53 | char *optstr=NULL; | 53 | char *optstr=NULL; |
| 54 | 54 | ||
| 55 | plan_tests(9); | 55 | plan_tests(10); |
| 56 | 56 | ||
| 57 | optstr=list2str(np_get_defaults("section@./config-tiny.ini", "check_disk")); | 57 | optstr=list2str(np_get_defaults("section@./config-tiny.ini", "check_disk")); |
| 58 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "config-tiny.ini's section as expected"); | 58 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "config-tiny.ini's section as expected"); |
| 59 | my_free(optstr); | 59 | my_free(optstr); |
| 60 | 60 | ||
| 61 | optstr=list2str(np_get_defaults("@./config-tiny.ini", "section")); | 61 | optstr=list2str(np_get_defaults("@./config-tiny.ini", "section")); |
| 62 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "Used default section name, without specific"); | 62 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "Used default section name, without specific"); |
| 63 | my_free(optstr); | 63 | my_free(optstr); |
| 64 | 64 | ||
| 65 | optstr=list2str(np_get_defaults("section_unknown@./config-tiny.ini", "section")); | 65 | optstr=list2str(np_get_defaults("section_unknown@./config-tiny.ini", "section")); |
| 66 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "Used default section name over specified one"); | 66 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "Used default section name over specified one"); |
| 67 | my_free(optstr); | 67 | my_free(optstr); |
| 68 | 68 | ||
| 69 | optstr=list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk")); | 69 | optstr=list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk")); |
| @@ -90,6 +90,10 @@ main (int argc, char **argv) | |||
| 90 | ok( !strcmp(optstr, "-u=admin -p=secret"), "plugin.ini's check_mysql2 as expected"); | 90 | ok( !strcmp(optstr, "-u=admin -p=secret"), "plugin.ini's check_mysql2 as expected"); |
| 91 | my_free(optstr); | 91 | my_free(optstr); |
| 92 | 92 | ||
| 93 | optstr=list2str(np_get_defaults("check space_and_flags@./plugin.ini", "check_disk")); | ||
| 94 | ok( !strcmp(optstr, "--foo=bar -a -b --bar"), "plugin.ini space in stanza and flag arguments"); | ||
| 95 | my_free(optstr); | ||
| 96 | |||
| 93 | return exit_status(); | 97 | return exit_status(); |
| 94 | } | 98 | } |
| 95 | 99 | ||
