diff options
-rw-r--r-- | src/basic/util.c | 6 | ||||
-rw-r--r-- | src/test/test-util.c | 6 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/basic/util.c b/src/basic/util.c index 3e90456dd3..3989b415fa 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -5913,9 +5913,11 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra break; case DOUBLE_QUOTE: - if (c == 0) + if (c == 0) { + if (flags & EXTRACT_RELAX) + goto finish_force_terminate; return -EINVAL; - else if (c == '\"') + } else if (c == '\"') state = VALUE; else if (c == '\\') state = DOUBLE_QUOTE_ESCAPE; diff --git a/src/test/test-util.c b/src/test/test-util.c index 503e840803..b5d9d01ba0 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -1639,6 +1639,12 @@ static void test_extract_first_word(void) { free(t); 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"; assert_se(extract_first_word(&p, &t, NULL, 0) > 0); assert_se(streq(t, "yay\'foo\'bar")); |