1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-14 15:21:37 +03:00

Merge pull request #704 from richardmaw-codethink/empty-arg-unquote

unquote_first_word: parse ` '' ` as an empty argument instead of no arg
This commit is contained in:
Daniel Mack 2015-07-24 19:49:29 +02:00
commit b83b298102
2 changed files with 21 additions and 4 deletions

View File

@ -5729,13 +5729,19 @@ int unquote_first_word(const char **p, char **ret, UnquoteFlags flags) {
case VALUE: case VALUE:
if (c == 0) if (c == 0)
goto finish; goto finish;
else if (c == '\'') else if (c == '\'') {
if (!GREEDY_REALLOC(s, allocated, sz+1))
return -ENOMEM;
state = SINGLE_QUOTE; state = SINGLE_QUOTE;
else if (c == '\\') } else if (c == '\\')
state = VALUE_ESCAPE; state = VALUE_ESCAPE;
else if (c == '\"') else if (c == '\"') {
if (!GREEDY_REALLOC(s, allocated, sz+1))
return -ENOMEM;
state = DOUBLE_QUOTE; state = DOUBLE_QUOTE;
else if (strchr(WHITESPACE, c)) } else if (strchr(WHITESPACE, c))
state = SPACE; state = SPACE;
else { else {
if (!GREEDY_REALLOC(s, allocated, sz+2)) if (!GREEDY_REALLOC(s, allocated, sz+2))

View File

@ -1689,6 +1689,17 @@ static void test_unquote_first_word(void) {
assert_se(streq(t, "\\w+\b")); assert_se(streq(t, "\\w+\b"));
free(t); free(t);
assert_se(p == original + 5); assert_se(p == original + 5);
p = original = "-N ''";
assert_se(unquote_first_word(&p, &t, UNQUOTE_CUNESCAPE) > 0);
assert_se(streq(t, "-N"));
free(t);
assert_se(p == original + 3);
assert_se(unquote_first_word(&p, &t, UNQUOTE_CUNESCAPE) > 0);
assert_se(streq(t, ""));
free(t);
assert_se(p == original + 5);
} }
static void test_unquote_first_word_and_warn(void) { static void test_unquote_first_word_and_warn(void) {