mirror of
https://github.com/systemd/systemd.git
synced 2024-12-26 03:22:00 +03:00
shared/conf-parser,networkd: EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE → EXTRACT_UNQUOTE
It's hard to even say what exactly this combination means. Escaping is necessary when quoting to have quotes within the string. So the escaping of quote characters is inherently tied to quoting. When unquoting, it seems natural to remove escaping which was done for the quoting purposes. But with both flags we would be expected to re-add this escaping after unqouting? Or maybe keep the escaping which is not necessary for quoting but otherwise present? This all seems too complicated, let's just forbid such usage and always fully unescape when unquoting.
This commit is contained in:
parent
fa8b675ae0
commit
8a07b4033e
@ -28,6 +28,8 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
|
||||
|
||||
assert(p);
|
||||
assert(ret);
|
||||
/* Those two don't make sense together. */
|
||||
assert(!FLAGS_SET(flags, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE));
|
||||
|
||||
/* Bail early if called after last value or with no input */
|
||||
if (!*p)
|
||||
|
@ -254,7 +254,7 @@ int config_parse_match_strv(
|
||||
for (;;) {
|
||||
_cleanup_free_ char *word = NULL, *k = NULL;
|
||||
|
||||
r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
|
||||
r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
|
||||
if (r == 0)
|
||||
return 0;
|
||||
if (r == -ENOMEM)
|
||||
|
@ -758,7 +758,7 @@ int config_parse_strv(
|
||||
for (;;) {
|
||||
char *word = NULL;
|
||||
|
||||
r = extract_first_word(&rvalue, &word, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
|
||||
r = extract_first_word(&rvalue, &word, NULL, EXTRACT_UNQUOTE);
|
||||
if (r == 0)
|
||||
break;
|
||||
if (r == -ENOMEM)
|
||||
|
@ -83,6 +83,30 @@ static void test_extract_first_word(void) {
|
||||
free(t);
|
||||
assert_se(isempty(p));
|
||||
|
||||
p = original = "KEY=val \"KEY2=val with space\" \"KEY3=val with \\\"quotation\\\"\"";
|
||||
assert_se(extract_first_word(&p, &t, NULL, EXTRACT_UNQUOTE) == 1);
|
||||
assert_se(streq(t, "KEY=val"));
|
||||
free(t);
|
||||
assert_se(extract_first_word(&p, &t, NULL, EXTRACT_UNQUOTE) == 1);
|
||||
assert_se(streq(t, "KEY2=val with space"));
|
||||
free(t);
|
||||
assert_se(extract_first_word(&p, &t, NULL, EXTRACT_UNQUOTE) == 1);
|
||||
assert_se(streq(t, "KEY3=val with \"quotation\""));
|
||||
free(t);
|
||||
assert_se(isempty(p));
|
||||
|
||||
p = original = "KEY=val \"KEY2=val space\" \"KEY3=val with \\\"quotation\\\"\"";
|
||||
assert_se(extract_first_word(&p, &t, NULL, EXTRACT_RETAIN_ESCAPE) == 1);
|
||||
assert_se(streq(t, "KEY=val"));
|
||||
free(t);
|
||||
assert_se(extract_first_word(&p, &t, NULL, EXTRACT_RETAIN_ESCAPE) == 1);
|
||||
assert_se(streq(t, "\"KEY2=val"));
|
||||
free(t);
|
||||
assert_se(extract_first_word(&p, &t, NULL, EXTRACT_RETAIN_ESCAPE) == 1);
|
||||
assert_se(streq(t, "space\""));
|
||||
free(t);
|
||||
assert_se(startswith(p, "\"KEY3="));
|
||||
|
||||
p = original = "\'fooo";
|
||||
assert_se(extract_first_word(&p, &t, NULL, EXTRACT_UNQUOTE) == -EINVAL);
|
||||
assert_se(p == original + 5);
|
||||
|
Loading…
Reference in New Issue
Block a user