aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYaroslav de la Peña Smirnov <yps@yaroslavps.com>2021-09-22 19:49:33 +0300
committerYaroslav de la Peña Smirnov <yps@yaroslavps.com>2021-09-22 19:49:33 +0300
commitdc6d7befaa0de08814d4aaf85838faaf3fec8671 (patch)
tree23e6170d5a751fe1d57f8d7b1adbe524f2cd2b5d /src
parent699f595d086820f8e016195b9ad3b5b90dad17d8 (diff)
downloadparcini-dc6d7befaa0de08814d4aaf85838faaf3fec8671.tar.gz
parcini-dc6d7befaa0de08814d4aaf85838faaf3fec8671.zip
Fix parcini treating one key characters as errors
Diffstat (limited to 'src')
-rw-r--r--src/parcini.c6
-rw-r--r--src/tests/parcini.c11
2 files changed, 11 insertions, 6 deletions
diff --git a/src/parcini.c b/src/parcini.c
index 7fa8247..8434685 100644
--- a/src/parcini.c
+++ b/src/parcini.c
@@ -144,6 +144,9 @@ parcini_parse_next_line(parcini_t *parser, struct parcini_line *parsed)
parsed->section = parser->last_section;
char *delim = strchr(start, '=');
+ if (start == delim) {
+ return PARCINI_KEY_PARSE_ERROR;
+ }
if (delim) {
char *cmnt = strchr(start, PARCINI_COMMENT_CHAR);
if (cmnt && cmnt < delim) {
@@ -153,9 +156,6 @@ parcini_parse_next_line(parcini_t *parser, struct parcini_line *parsed)
*end = '\0';
end -= 1;
rstrip(start, &end);
- if (start == end) {
- return PARCINI_KEY_PARSE_ERROR;
- }
parsed->key = start;
start = delim + 1;
diff --git a/src/tests/parcini.c b/src/tests/parcini.c
index f53ab09..90d5997 100644
--- a/src/tests/parcini.c
+++ b/src/tests/parcini.c
@@ -35,7 +35,7 @@ test_parcini_parse_file(void)
asserteq(res, PARCINI_KEYVALUE);
asserteq(line.lineno, 3);
asserteq(strcmp(line.section, ""), 0);
- asserteq(strcmp(line.key, "key3"), 0);
+ asserteq(strcmp(line.key, "3"), 0);
asserteq(line.value.type, PARCINI_VALUE_BOOLEAN);
asserteq(line.value.value.boolean, false);
@@ -115,14 +115,19 @@ test_parcini_parse_file(void)
/* line 15 */
res = parcini_parse_next_line(parser, &line);
- asserteq(res, PARCINI_EMPTY_LINE);
+ asserteq(res, PARCINI_KEY_PARSE_ERROR);
asserteq(line.lineno, 15);
/* line 16 */
res = parcini_parse_next_line(parser, &line);
- asserteq(res, PARCINI_SECTION_PARSE_ERROR);
+ asserteq(res, PARCINI_EMPTY_LINE);
asserteq(line.lineno, 16);
+ /* line 17 */
+ res = parcini_parse_next_line(parser, &line);
+ asserteq(res, PARCINI_SECTION_PARSE_ERROR);
+ asserteq(line.lineno, 17);
+
/* EOF */
res = parcini_parse_next_line(parser, &line);
asserteq(res, PARCINI_EOF);