From 7b00f957fece2bc63bf624b1c77291288145c94c Mon Sep 17 00:00:00 2001 From: wyu <97944796+wyu71@users.noreply.github.com> Date: Wed, 12 Aug 2026 09:43:57 +0800 Subject: [PATCH] strv: drop the escape_separator flag from strv_join_full() Now that fstab_filter_options() no longer uses strv_join_full() with escape_separator=true (it splits with EXTRACT_UNESCAPE_RELAX and joins the kept options verbatim), the escape_separator flag has no users. Drop it from strv_join_full() and its wrapper strv_join(), and update the remaining callers in kernel-install and the tests accordingly. --- src/basic/strv.c | 20 +++----------------- src/basic/strv.h | 4 ++-- src/kernel-install/kernel-install.c | 4 ++-- src/shared/options.c | 2 +- src/test/test-strv.c | 27 +++++++-------------------- 5 files changed, 15 insertions(+), 42 deletions(-) diff --git a/src/basic/strv.c b/src/basic/strv.c index eb3cd8d4b2..77057f12a6 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -529,7 +529,7 @@ int strv_split_colon_pairs(char ***t, const char *s) { return (int) n; } -char* strv_join_full(char * const *l, const char *separator, const char *prefix, bool escape_separator) { +char* strv_join_full(char * const *l, const char *separator, const char *prefix) { char *r, *e; size_t n, k, m; @@ -539,17 +539,12 @@ char* strv_join_full(char * const *l, const char *separator, const char *prefix, k = strlen(separator); m = strlen_ptr(prefix); - if (escape_separator) /* If the separator was multi-char, we wouldn't know how to escape it. */ - assert(k == 1); - n = 0; STRV_FOREACH(s, l) { if (s != l) n += k; - bool needs_escaping = escape_separator && strchr(*s, *separator); - - n += m + strlen(*s) * (1 + needs_escaping); + n += m + strlen(*s); } r = new(char, n+1); @@ -564,16 +559,7 @@ char* strv_join_full(char * const *l, const char *separator, const char *prefix, if (prefix) e = stpcpy(e, prefix); - bool needs_escaping = escape_separator && strchr(*s, *separator); - - if (needs_escaping) - for (size_t i = 0; (*s)[i]; i++) { - if ((*s)[i] == *separator) - *(e++) = '\\'; - *(e++) = (*s)[i]; - } - else - e = stpcpy(e, *s); + e = stpcpy(e, *s); } *e = 0; diff --git a/src/basic/strv.h b/src/basic/strv.h index 2a0c2730d1..5afd345358 100644 --- a/src/basic/strv.h +++ b/src/basic/strv.h @@ -120,9 +120,9 @@ char** strv_split_newlines(const char *s); * string in the vector is an empty string. */ int strv_split_colon_pairs(char ***t, const char *s); -char* strv_join_full(char * const *l, const char *separator, const char *prefix, bool escape_separator); +char* strv_join_full(char * const *l, const char *separator, const char *prefix); static inline char *strv_join(char * const *l, const char *separator) { - return strv_join_full(l, separator, NULL, false); + return strv_join_full(l, separator, NULL); } bool strv_overlap(char * const *a, char * const *b) _pure_; diff --git a/src/kernel-install/kernel-install.c b/src/kernel-install/kernel-install.c index 69fdbcfc34..53f203f665 100644 --- a/src/kernel-install/kernel-install.c +++ b/src/kernel-install/kernel-install.c @@ -1093,10 +1093,10 @@ static int context_execute(Context *c) { return r; if (DEBUG_LOGGING) { - _cleanup_free_ char *x = strv_join_full(c->plugins, "", "\n ", /* escape_separator= */ false); + _cleanup_free_ char *x = strv_join_full(c->plugins, "", "\n "); log_debug("Using plugins: %s", strna(x)); - _cleanup_free_ char *y = strv_join_full(c->envp, "", "\n ", /* escape_separator= */ false); + _cleanup_free_ char *y = strv_join_full(c->envp, "", "\n "); log_debug("Plugin environment: %s", strna(y)); _cleanup_free_ char *z = strv_join(strv_skip(c->argv, 1), " "); diff --git a/src/shared/options.c b/src/shared/options.c index 1a24106fc5..68a275037c 100644 --- a/src/shared/options.c +++ b/src/shared/options.c @@ -64,7 +64,7 @@ static int partial_match_error( assert(strv_length(s) == n_partial_matches); - _cleanup_free_ char *p = strv_join_full(s, ", ", /* prefix= */ NULL, /* escape_separator= */ false); + _cleanup_free_ char *p = strv_join(s, ", "); return log_full_errno(LOG_ERR + state->log_level_shift, SYNTHETIC_ERRNO(EINVAL), "%s: option '%s' is ambiguous; possibilities: %s", diff --git a/src/test/test-strv.c b/src/test/test-strv.c index 53156a9412..105f34fe8d 100644 --- a/src/test/test-strv.c +++ b/src/test/test-strv.c @@ -159,44 +159,31 @@ TEST(strv_join) { } TEST(strv_join_full) { - _cleanup_free_ char *p = strv_join_full((char **)input_table_multiple, ", ", "foo", false); + _cleanup_free_ char *p = strv_join_full((char **)input_table_multiple, ", ", "foo"); assert_se(p); ASSERT_STREQ(p, "fooone, footwo, foothree"); - _cleanup_free_ char *q = strv_join_full((char **)input_table_multiple, ";", "foo", false); + _cleanup_free_ char *q = strv_join_full((char **)input_table_multiple, ";", "foo"); assert_se(q); ASSERT_STREQ(q, "fooone;footwo;foothree"); - _cleanup_free_ char *r = strv_join_full(STRV_MAKE("a", "a;b", "a:c"), ";", NULL, true); - assert_se(r); - ASSERT_STREQ(r, "a;a\\;b;a:c"); - - _cleanup_free_ char *s = strv_join_full(STRV_MAKE("a", "a;b", "a;;c", ";", ";x"), ";", NULL, true); - assert_se(s); - ASSERT_STREQ(s, "a;a\\;b;a\\;\\;c;\\;;\\;x"); - - _cleanup_free_ char *t = strv_join_full(STRV_MAKE("a", "a;b", "a:c", ";"), ";", "=", true); - assert_se(t); - ASSERT_STREQ(t, "=a;=a\\;b;=a:c;=\\;"); - t = mfree(t); - - _cleanup_free_ char *u = strv_join_full((char **)input_table_multiple, NULL, "foo", false); + _cleanup_free_ char *u = strv_join_full((char **)input_table_multiple, NULL, "foo"); assert_se(u); ASSERT_STREQ(u, "fooone footwo foothree"); - _cleanup_free_ char *v = strv_join_full((char **)input_table_one, ", ", "foo", false); + _cleanup_free_ char *v = strv_join_full((char **)input_table_one, ", ", "foo"); assert_se(v); ASSERT_STREQ(v, "fooone"); - _cleanup_free_ char *w = strv_join_full((char **)input_table_none, ", ", "foo", false); + _cleanup_free_ char *w = strv_join_full((char **)input_table_none, ", ", "foo"); assert_se(w); ASSERT_STREQ(w, ""); - _cleanup_free_ char *x = strv_join_full((char **)input_table_two_empties, ", ", "foo", false); + _cleanup_free_ char *x = strv_join_full((char **)input_table_two_empties, ", ", "foo"); assert_se(x); ASSERT_STREQ(x, "foo, foo"); - _cleanup_free_ char *y = strv_join_full((char **)input_table_one_empty, ", ", "foo", false); + _cleanup_free_ char *y = strv_join_full((char **)input_table_one_empty, ", ", "foo"); assert_se(y); ASSERT_STREQ(y, "foo"); }