Skip to content

Commit

Permalink
Make inline comments work on subsequent lines of multiline values (#140)
Browse files Browse the repository at this point in the history
This is a bug fix that makes inih's behaviour here work as per Python's
ConfigParser, which is what inih behaviour is (loosely) based on.

Thanks @silly2020 for the report. See
#120 (comment)
  • Loading branch information
benhoyt committed Jul 12, 2022
1 parent ef9da8f commit bd798c5
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
}
#if INI_ALLOW_MULTILINE
else if (*prev_name && *start && start > line) {
#if INI_ALLOW_INLINE_COMMENTS
end = find_chars_or_comment(start, NULL);
if (*end)
*end = '\0';
rstrip(start);
#endif
/* Non-blank line with leading whitespace, treat as continuation
of previous name's value (as per Python configparser). */
if (!HANDLER(user, section, prev_name, start) && !error)
Expand Down
2 changes: 2 additions & 0 deletions tests/baseline_allow_no_value.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ user_error.ini: e=3 user=104
... multi=the quick;
... multi=brown fox;
... name=bob smith;
... foo=bar;
... foo=Hi World;
multi_line.ini: e=0 user=105
... indented;
bad_multi.ini: e=0 user=106
Expand Down
2 changes: 2 additions & 0 deletions tests/baseline_call_handler_on_new_section.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ user_error.ini: e=3 user=104
... multi=the quick;
... multi=brown fox;
... name=bob smith;
... foo=bar;
... foo=Hi World;
multi_line.ini: e=0 user=105
bad_multi.ini: e=1 user=105
... [bom_section]
Expand Down
2 changes: 2 additions & 0 deletions tests/baseline_disallow_inline_comments.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ user_error.ini: e=3 user=104
... multi=the quick;
... multi=brown fox;
... name=bob smith ; comment line 1;
... foo=bar ;c1;
... foo=Hi World ;c2;
multi_line.ini: e=0 user=105
bad_multi.ini: e=1 user=105
... [bom_section]
Expand Down
2 changes: 2 additions & 0 deletions tests/baseline_handler_lineno.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ user_error.ini: e=3 user=104
... multi=the quick; line 12
... multi=brown fox; line 13
... name=bob smith; line 14
... foo=bar; line 16
... foo=Hi World; line 17
multi_line.ini: e=0 user=105
bad_multi.ini: e=1 user=105
... [bom_section]
Expand Down
2 changes: 2 additions & 0 deletions tests/baseline_heap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ user_error.ini: e=3 user=104
... multi=the quick;
... multi=brown fox;
... name=bob smith;
... foo=bar;
... foo=Hi World;
multi_line.ini: e=0 user=105
bad_multi.ini: e=1 user=105
... [bom_section]
Expand Down
2 changes: 2 additions & 0 deletions tests/baseline_heap_max_line.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ user_error.ini: e=3 user=104
... name=bob smith;
... name=comment line 1;
... name=comment line 2;
... foo=bar;
... foo=Hi World;
multi_line.ini: e=5 user=105
bad_multi.ini: e=1 user=105
... [bom_section]
Expand Down
2 changes: 2 additions & 0 deletions tests/baseline_heap_realloc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ user_error.ini: e=3 user=104
... multi=the quick;
... multi=brown fox;
... name=bob smith;
... foo=bar;
... foo=Hi World;
multi_line.ini: e=0 user=105
bad_multi.ini: e=1 user=105
... [bom_section]
Expand Down
2 changes: 2 additions & 0 deletions tests/baseline_heap_realloc_max_line.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ user_error.ini: e=3 user=104
... name=bob smith;
... name=comment line 1;
... name=comment line 2;
... foo=bar;
... foo=Hi World;
multi_line.ini: e=5 user=105
bad_multi.ini: e=1 user=105
... [bom_section]
Expand Down
2 changes: 2 additions & 0 deletions tests/baseline_multi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ user_error.ini: e=3 user=104
... multi=the quick;
... multi=brown fox;
... name=bob smith;
... foo=bar;
... foo=Hi World;
multi_line.ini: e=0 user=105
bad_multi.ini: e=1 user=105
... [bom_section]
Expand Down
2 changes: 2 additions & 0 deletions tests/baseline_multi_max_line.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ user_error.ini: e=3 user=104
... name=bob smith;
... name=comment line 1;
... name=comment line 2;
... foo=bar;
... foo=Hi World;
multi_line.ini: e=5 user=105
bad_multi.ini: e=1 user=105
... [bom_section]
Expand Down
1 change: 1 addition & 0 deletions tests/baseline_single.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ user_error.ini: e=3 user=104
... single=ghi;
... multi=the quick;
... name=bob smith;
... foo=bar;
multi_line.ini: e=4 user=105
bad_multi.ini: e=1 user=105
... [bom_section]
Expand Down
2 changes: 2 additions & 0 deletions tests/baseline_stop_on_first_error.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ user_error.ini: e=3 user=104
... multi=the quick;
... multi=brown fox;
... name=bob smith;
... foo=bar;
... foo=Hi World;
multi_line.ini: e=0 user=105
bad_multi.ini: e=1 user=105
... [bom_section]
Expand Down
2 changes: 2 additions & 0 deletions tests/multi_line.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ multi: the quick
brown fox
name = bob smith ; comment line 1
; comment line 2
foo = bar ;c1
Hi World ;c2

0 comments on commit bd798c5

Please sign in to comment.