1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 09:21:26 +03:00

Merge pull request #11355 from yuwata/rfe-11343

conf-parse: accept whitespaces before comments
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-01-08 15:07:33 +01:00 committed by GitHub
commit f0560c7453
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 7 deletions

View File

@ -137,7 +137,7 @@ static int next_assignment(
/* Warn about unknown non-extension fields. */ /* Warn about unknown non-extension fields. */
if (!(flags & CONFIG_PARSE_RELAXED) && !startswith(lvalue, "X-")) if (!(flags & CONFIG_PARSE_RELAXED) && !startswith(lvalue, "X-"))
log_syntax(unit, LOG_WARNING, filename, line, 0, "Unknown lvalue '%s' in section '%s'", lvalue, section); log_syntax(unit, LOG_WARNING, filename, line, 0, "Unknown lvalue '%s' in section '%s', ignoring", lvalue, section);
return 0; return 0;
} }
@ -321,7 +321,7 @@ int config_parse(const char *unit,
return r; return r;
} }
if (strchr(COMMENTS, *buf)) if (strchr(COMMENTS, *skip_leading_chars(buf, WHITESPACE)))
continue; continue;
l = buf; l = buf;

View File

@ -247,6 +247,18 @@ static const char* const config_file[] = {
"2\\\n" "2\\\n"
"3\n", "3\n",
"[Section]\n"
" #hogehoge\\\n" /* whitespaces before comments */
" setting1=1\\\n" /* whitespaces before key */
"2\\\n"
"3\n",
"[Section]\n"
" setting1=1\\\n" /* whitespaces before key */
" #hogehoge\\\n" /* commented out line prefixed with whitespaces in continuation */
"2\\\n"
"3\n",
"[Section]\n" "[Section]\n"
"setting1=1\\\n" /* continuation with extra trailing backslash at the end */ "setting1=1\\\n" /* continuation with extra trailing backslash at the end */
"2\\\n" "2\\\n"
@ -323,27 +335,27 @@ static void test_config_parse(unsigned i, const char *s) {
assert_se(streq(setting1, "1")); assert_se(streq(setting1, "1"));
break; break;
case 4 ... 7: case 4 ... 9:
assert_se(r == 0); assert_se(r == 0);
assert_se(streq(setting1, "1 2 3")); assert_se(streq(setting1, "1 2 3"));
break; break;
case 8: case 10:
assert_se(r == 0); assert_se(r == 0);
assert_se(streq(setting1, "1\\\\ \\\\2")); assert_se(streq(setting1, "1\\\\ \\\\2"));
break; break;
case 9: case 11:
assert_se(r == 0); assert_se(r == 0);
assert_se(streq(setting1, x1000("ABCD"))); assert_se(streq(setting1, x1000("ABCD")));
break; break;
case 10 ... 11: case 12 ... 13:
assert_se(r == 0); assert_se(r == 0);
assert_se(streq(setting1, x1000("ABCD") " foobar")); assert_se(streq(setting1, x1000("ABCD") " foobar"));
break; break;
case 12 ... 13: case 14 ... 15:
assert_se(r == -ENOBUFS); assert_se(r == -ENOBUFS);
assert_se(setting1 == NULL); assert_se(setting1 == NULL);
break; break;