mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
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:
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user