basic/strv: fix splitting of strings with escape characters

Plain strv_split() should not care if the strings contains backslashes
or quote characters. But extract_first_word() interprets backslashes
unless EXTRACT_RETAIN_ESCAPE is given.

I wonder how it's possible that nobody noticed this before. I think this
code was introduced in 0645b83a40.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2022-05-06 18:23:06 +02:00
parent 34c2d32cf9
commit b38a9d2d77
2 changed files with 16 additions and 1 deletions

View File

@@ -77,7 +77,7 @@ int strv_split_full(char ***t, const char *s, const char *separators, ExtractFla
static inline char** strv_split(const char *s, const char *separators) {
char **ret;
if (strv_split_full(&ret, s, separators, 0) < 0)
if (strv_split_full(&ret, s, separators, EXTRACT_RETAIN_ESCAPE) < 0)
return NULL;
return ret;

View File

@@ -317,6 +317,21 @@ TEST(strv_split) {
assert_se(strv_split_full(&l, "\\", NULL, EXTRACT_UNQUOTE | EXTRACT_RELAX | EXTRACT_UNESCAPE_RELAX) == 1);
assert_se(strv_equal(l, STRV_MAKE("\\")));
l = strv_free_erase(l);
assert_se(l = strv_split("\\", NULL));
assert_se(strv_equal(l, STRV_MAKE("\\")));
l = strv_free_erase(l);
assert_se(l = strv_split("aa\\ bb\\", NULL));
assert_se(strv_equal(l, STRV_MAKE("aa\\", "bb\\")));
l = strv_free_erase(l);
assert_se(l = strv_split("aa\" bb'", NULL));
assert_se(strv_equal(l, STRV_MAKE("aa\"", "bb'")));
}
TEST(strv_split_empty) {