Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make inline comments work on subsequent lines of multiline values #140

Merged
merged 2 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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