From 0aa086065c5bb0eef3ea53ed0f3e464ebcbb6853 Mon Sep 17 00:00:00 2001 From: Peter Colberg Date: Sun, 3 Jan 2021 14:08:25 -0500 Subject: Require trailing comment to be preceded by a space or tab Fixes `word-delimiters` option to not ignore `#` and subsequent characters. Closes #270 --- config.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index bf184a16..883cf27c 100644 --- a/config.c +++ b/config.c @@ -1731,9 +1731,18 @@ parse_config_file(FILE *f, struct config *conf, const char *path, bool errors_ar if (line[0] == '\0' || line[0] == '#') continue; - /* Split up into key/value pair + trailing comment */ - char *key_value = strtok(line, "#"); - char UNUSED *comment = strtok(NULL, "\n"); + /* Split up into key/value pair + trailing comment separated by blank */ + char *key_value = line; + char *comment = line; + while (comment[0] != '\0') { + const char c = comment[0]; + comment++; + if (isblank(c) && comment[0] == '#') { + comment[0] = '\0'; /* Terminate key/value pair */ + comment++; + break; + } + } /* Check for new section */ if (key_value[0] == '[') { -- cgit v1.3