Fix issue noted by @jgroffen where if both : and = were used on a line, = would take precedence ( https://github.com/benhoyt/inih/pull/44)
diff --git a/ini.c b/ini.c
index 63b69fc..8809419 100644
--- a/ini.c
+++ b/ini.c
@@ -41,13 +41,13 @@
return (char*)s;
}
-/* Return pointer to first char c or ';' comment in given string, or pointer to
- null at end of string if neither found. ';' must be prefixed by a whitespace
- character to register as a comment. */
-static char* find_char_or_comment(const char* s, char c)
+/* Return pointer to first char (of chars) or ';' comment in given string, or
+ pointer to null at end of string if neither found. ';' must be prefixed by
+ a whitespace character to register as a comment. */
+static char* find_chars_or_comment(const char* s, const char* chars)
{
int was_whitespace = 0;
- while (*s && *s != c && !(was_whitespace && *s == ';')) {
+ while (*s && (!chars || !strchr(chars, *s)) && !(was_whitespace && *s == ';')) {
was_whitespace = isspace((unsigned char)(*s));
s++;
}
@@ -116,7 +116,7 @@
#endif
else if (*start == '[') {
/* A "[section]" line */
- end = find_char_or_comment(start + 1, ']');
+ end = find_chars_or_comment(start + 1, "]");
if (*end == ']') {
*end = '\0';
strncpy0(section, start + 1, sizeof(section));
@@ -129,15 +129,12 @@
}
else if (*start && *start != ';') {
/* Not a comment, must be a name[=:]value pair */
- end = find_char_or_comment(start, '=');
- if (*end != '=') {
- end = find_char_or_comment(start, ':');
- }
+ end = find_chars_or_comment(start, "=:");
if (*end == '=' || *end == ':') {
*end = '\0';
name = rstrip(start);
value = lskip(end + 1);
- end = find_char_or_comment(value, '\0');
+ end = find_chars_or_comment(value, NULL);
if (*end == ';')
*end = '\0';
rstrip(value);
diff --git a/tests/baseline_multi.txt b/tests/baseline_multi.txt
index eb87297..dfc323b 100644
--- a/tests/baseline_multi.txt
+++ b/tests/baseline_multi.txt
@@ -14,6 +14,10 @@
... Content-Type=text/html;
... foo=bar;
... adams=42;
+... funny1=with = equals;
+... funny2=with : colons;
+... funny3=two = equals;
+... funny4=two : colons;
normal.ini: e=0 user=101
... [section1]
... name1=value1;
diff --git a/tests/baseline_single.txt b/tests/baseline_single.txt
index e638038..3693085 100644
--- a/tests/baseline_single.txt
+++ b/tests/baseline_single.txt
@@ -14,6 +14,10 @@
... Content-Type=text/html;
... foo=bar;
... adams=42;
+... funny1=with = equals;
+... funny2=with : colons;
+... funny3=two = equals;
+... funny4=two : colons;
normal.ini: e=0 user=101
... [section1]
... name1=value1;
diff --git a/tests/baseline_stop_on_first_error.txt b/tests/baseline_stop_on_first_error.txt
index 05dfef8..c5fdbcb 100644
--- a/tests/baseline_stop_on_first_error.txt
+++ b/tests/baseline_stop_on_first_error.txt
@@ -14,6 +14,10 @@
... Content-Type=text/html;
... foo=bar;
... adams=42;
+... funny1=with = equals;
+... funny2=with : colons;
+... funny3=two = equals;
+... funny4=two : colons;
normal.ini: e=0 user=101
... [section1]
... name1=value1;
diff --git a/tests/normal.ini b/tests/normal.ini
index bd5bcd7..222b477 100644
--- a/tests/normal.ini
+++ b/tests/normal.ini
@@ -23,3 +23,7 @@
Content-Type: text/html
foo:bar
adams : 42
+funny1 : with = equals
+funny2 = with : colons
+funny3 = two = equals
+funny4 : two : colons