-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tst-comments2: comment sign in quoted string
The comment character (e.g. '#') in a quoted string should not be handled as comment but as part of the value. See linux-pam/linux-pam#13
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
KEY1="a#b" | ||
KEY2="a#b" # with real comment | ||
KEY3=a#b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#ifdef HAVE_CONFIG_H | ||
# include <config.h> | ||
#endif | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include "libeconf.h" | ||
|
||
/* Test case: | ||
variable contains comment character in a quoted string | ||
*/ | ||
|
||
static int | ||
check_key(econf_file *key_file, char *key, char *expected_val) | ||
{ | ||
char *val = NULL; | ||
econf_err error = econf_getStringValue (key_file, "", key, &val); | ||
if (expected_val == NULL) | ||
{ | ||
if (val == NULL) | ||
return 0; | ||
|
||
fprintf (stderr, "ERROR: %s has value \"%s\"\n", key, val); | ||
return 1; | ||
} | ||
if (val == NULL || strlen(val) == 0) | ||
{ | ||
fprintf (stderr, "ERROR: %s returns nothing! (%s)\n", key, | ||
econf_errString(error)); | ||
return 1; | ||
} | ||
if (strcmp (val, expected_val) != 0) | ||
{ | ||
fprintf (stderr, "ERROR: %s is not \"%s\", got [%s]\n", key, expected_val, val); | ||
return 1; | ||
} | ||
|
||
printf("Ok: %s=%s\n", key, val); | ||
free (val); | ||
return 0; | ||
} | ||
|
||
int | ||
main(void) | ||
{ | ||
econf_file *key_file = NULL; | ||
int retval = 0; | ||
econf_err error; | ||
|
||
error = econf_readConfig (&key_file, | ||
NULL, | ||
"", | ||
"env", | ||
"conf", "=", "#"); | ||
if (error) | ||
{ | ||
fprintf (stderr, "ERROR: econf_readConfig: %s\n", | ||
econf_errString(error)); | ||
return 1; | ||
} | ||
|
||
if (check_key(key_file, "KEY1", "a#b") != 0) | ||
retval = 1; | ||
if (check_key(key_file, "KEY2", "a#b") != 0) | ||
retval = 1; | ||
if (check_key(key_file, "KEY3", "a") != 0) | ||
retval = 1; | ||
|
||
econf_free (key_file); | ||
|
||
return retval; | ||
} |