1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-08 02:57:16 +03:00

Merge pull request #1642 from evverx/allow-unbalanced-double-quote-in-relax-mode

util: allow unbalanced double quote in EXTRACT_QUOTES|EXTRACT_RELAX mode
This commit is contained in:
Lennart Poettering 2015-10-22 12:20:12 +02:00
commit b2fe9deb4f
2 changed files with 10 additions and 2 deletions

View File

@ -5913,9 +5913,11 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
break; break;
case DOUBLE_QUOTE: case DOUBLE_QUOTE:
if (c == 0) if (c == 0) {
if (flags & EXTRACT_RELAX)
goto finish_force_terminate;
return -EINVAL; return -EINVAL;
else if (c == '\"') } else if (c == '\"')
state = VALUE; state = VALUE;
else if (c == '\\') else if (c == '\\')
state = DOUBLE_QUOTE_ESCAPE; state = DOUBLE_QUOTE_ESCAPE;

View File

@ -1639,6 +1639,12 @@ static void test_extract_first_word(void) {
free(t); free(t);
assert_se(isempty(p)); assert_se(isempty(p));
p = original = "\"fooo";
assert_se(extract_first_word(&p, &t, NULL, EXTRACT_QUOTES|EXTRACT_RELAX) > 0);
assert_se(streq(t, "fooo"));
free(t);
assert_se(isempty(p));
p = original = "yay\'foo\'bar"; p = original = "yay\'foo\'bar";
assert_se(extract_first_word(&p, &t, NULL, 0) > 0); assert_se(extract_first_word(&p, &t, NULL, 0) > 0);
assert_se(streq(t, "yay\'foo\'bar")); assert_se(streq(t, "yay\'foo\'bar"));