Fwd: [PATCH] This simple patch allows comments in the middle of a line.
From 4a87185f577d61f51c94e9b158d602460c795330 Mon Sep 17 00:00:00 2001 From: Fabiano Furtado <fabianofurtado <at> gmail <dot> com> Date: Sun, 24 Jul 2022 16:44:31 -0300 Subject: [PATCH] As described in https://archlinux.org/pacman/pacman.conf.5.html#_description, "Comments are only supported by beginning a line with the hash (#) symbol. Comments cannot begin in the middle of a line.". This patch allows comments in the middle of a line. Example: LogFile = /tmp/pacman.log#/var/log/pacman.log
Signed-off-by: Fabiano Furtado <fabianofurtado <at> gmail <dot> com> --- src/common/ini.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/common/ini.c b/src/common/ini.c index 410a2843..4d09d844 100644 --- a/src/common/ini.c +++ b/src/common/ini.c @@ -60,14 +60,22 @@ int parse_ini(const char *file, ini_parser_fn cb, void *data) } while(safe_fgets(line, PATH_MAX, fp)) { - char *key, *value; + char *key, *value, *comment; size_t line_len; linenum++; + if(line[0] == '#') { + continue; + } + + if((comment = strchr(line,'#')) != NULL) { + *comment = '\0'; + } + line_len = strtrim(line); - if(line_len == 0 || line[0] == '#') { + if(line_len == 0) { continue; } -- 2.37.1
Hi Fabiano, Fabiano Furtado writes:
From 4a87185f577d61f51c94e9b158d602460c795330 Mon Sep 17 00:00:00 2001 From: Fabiano Furtado <fabianofurtado <at> gmail <dot> com> Date: Sun, 24 Jul 2022 16:44:31 -0300 Subject: [PATCH] As described in https://archlinux.org/pacman/pacman.conf.5.html#_description, "Comments are
Fittingly, this URL shows why...
only supported by beginning a line with the hash (#) symbol. Comments cannot begin in the middle of a line.". This patch allows comments in the middle of a line. Example: LogFile = /tmp/pacman.log#/var/log/pacman.log
...this should not be allowed, because octothorpes may be valid values in some fields. In fact that's exactly why it was disallowed in commit 8a19c4a78251 ("ini: only recognize comments at beginning of line"). It might be ok to allow it only after whitespace, but since it's already caused problems I'd be inclined not to poke the bear again unless there's some compelling reason. Thanks, Chris
Hi, Chris! I didn't know about this commit 8a19c4a78251. Sorry for that. Indeed, there is no compelling reason to rollback this code. I just thought this '#' symbol isn't a valid value in some fields. Thanks! On Mon, Jul 25, 2022 at 9:54 AM Chris Down wrote:
Hi Fabiano,
Fabiano Furtado writes:
From 4a87185f577d61f51c94e9b158d602460c795330 Mon Sep 17 00:00:00 2001 From: Fabiano Furtado <fabianofurtado <at> gmail <dot> com> Date: Sun, 24 Jul 2022 16:44:31 -0300 Subject: [PATCH] As described in https://archlinux.org/pacman/pacman.conf.5.html#_description, "Comments are
Fittingly, this URL shows why...
only supported by beginning a line with the hash (#) symbol. Comments cannot begin in the middle of a line.". This patch allows comments in the middle of a line. Example: LogFile = /tmp/pacman.log#/var/log/pacman.log
...this should not be allowed, because octothorpes may be valid values in some fields.
In fact that's exactly why it was disallowed in commit 8a19c4a78251 ("ini: only recognize comments at beginning of line").
It might be ok to allow it only after whitespace, but since it's already caused problems I'd be inclined not to poke the bear again unless there's some compelling reason.
Thanks,
Chris
participants (2)
-
Chris Down
-
Fabiano Furtado