提交 54716a77 编写于 作者: E Emmanuel Leblond

Fix parsing with

上级 dd5acfba
......@@ -593,6 +593,12 @@ static line_status iniparser_line(
strstrip(key);
strlwc(key, key, len);
/* Don't strip spaces from values surrounded with quotes */
sta = LINE_VALUE ;
} else if (sscanf (line, "%[^=] = %[^;#]", key, value) == 2) {
/* Usual key=value without quotes, with or without comments */
strstrip(key);
strlwc(key, key, len);
strstrip(value);
/*
* sscanf cannot handle '' or "" as empty values
* this is done here
......@@ -600,13 +606,6 @@ static line_status iniparser_line(
if (!strcmp(value, "\"\"") || (!strcmp(value, "''"))) {
value[0]=0 ;
}
sta = LINE_VALUE ;
} else if (sscanf (line, "%[^=] = %[^;#]", key, value) == 2) {
/* Usual key=value without quotes, with or without comments */
strstrip(key);
strlwc(key, key, len);
strstrip(value);
sta = LINE_VALUE ;
} else if (sscanf(line, "%[^=] = %[;#]", key, value)==2
|| sscanf(line, "%[^=] %[=]", key, value) == 2) {
......
......@@ -487,6 +487,10 @@ void Test_iniparser_line(CuTest *tc)
CuAssertStrEquals(tc, "empty_value", key);
CuAssertStrEquals(tc, "", val);
CuAssertIntEquals(tc, LINE_VALUE, iniparser_line("empty_value = \t\n", section, key, val));
CuAssertStrEquals(tc, "empty_value", key);
CuAssertStrEquals(tc, "", val);
CuAssertIntEquals(tc, LINE_VALUE, iniparser_line("key =\tval # comment", section, key, val));
CuAssertStrEquals(tc, "key", key);
CuAssertStrEquals(tc, "val", val);
......@@ -502,10 +506,23 @@ void Test_iniparser_line(CuTest *tc)
CuAssertStrEquals(tc, "key", key);
CuAssertStrEquals(tc, " do_not_strip ", val);
CuAssertIntEquals(tc, LINE_VALUE, iniparser_line("key = ' '", section, key, val));
CuAssertStrEquals(tc, "key", key);
CuAssertStrEquals(tc, " ", val);
CuAssertIntEquals(tc, LINE_VALUE, iniparser_line("key = \"\"", section, key, val));
CuAssertStrEquals(tc, "key", key);
CuAssertStrEquals(tc, "", val);
CuAssertIntEquals(tc, LINE_VALUE, iniparser_line("key = ''", section, key, val));
CuAssertStrEquals(tc, "key", key);
CuAssertStrEquals(tc, "", val);
/* Test syntax error */
CuAssertIntEquals(tc, LINE_ERROR, iniparser_line("empty_value", section, key, val));
CuAssertIntEquals(tc, LINE_ERROR, iniparser_line("not finished\\", section, key, val));
CuAssertIntEquals(tc, LINE_ERROR, iniparser_line("0x42 / 0b101010", section, key, val));
}
void Test_iniparser_load(CuTest *tc)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册