From: Eric Bollengier Date: Fri, 11 Feb 2022 09:28:16 +0000 (+0100) Subject: Strip leading/ending spaces in plugutil_str_split_to_alist() X-Git-Tag: Beta-15.0.0~647 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d171f625a2f7b831fbf792340202c5c48296aa6a;p=thirdparty%2Fbacula.git Strip leading/ending spaces in plugutil_str_split_to_alist() The string "label: akeyword" was returning "label" and " akeyword" and the code was not designed to handle the extra space in the keyword. According to the current usage, it seems that the leading/ending white spaces are polluting the variables. --- diff --git a/bacula/src/plugins/fd/pluginlib/pluginlib.cpp b/bacula/src/plugins/fd/pluginlib/pluginlib.cpp index cb9087962..7ad0cd0c8 100644 --- a/bacula/src/plugins/fd/pluginlib/pluginlib.cpp +++ b/bacula/src/plugins/fd/pluginlib/pluginlib.cpp @@ -291,7 +291,7 @@ void plugutil_str_split_to_alist(alist *list, const char * str, const char sep) } /** - * @brief It splits a string `str` into a separate substrings split on `sep` character. + * @brief It splits a string `str` into a separate substrings split on `sep` character. Leading and trailing spaces are removed. * * @param list a list used to populate split results * @param str a string to split @@ -316,6 +316,12 @@ void plugutil_str_split_to_alist(alist &list, const char * str, const char sep) buf.c_str()[q - p] = '\0'; p = q + 1; // next element } + /* The following cleanup has been added to split strings such as + * item1: value => 'item1', 'value' and not 'item1', ' value' + */ + strip_leading_space(buf.c_str()); + strip_trailing_junk(buf.c_str()); + // in buf we have splitted string part const char * s = bstrdup(buf.c_str()); list.append((void*)s); diff --git a/bacula/src/plugins/fd/pluginlib/pluginlib.h b/bacula/src/plugins/fd/pluginlib/pluginlib.h index cbb89e9e7..fdd6f4214 100644 --- a/bacula/src/plugins/fd/pluginlib/pluginlib.h +++ b/bacula/src/plugins/fd/pluginlib/pluginlib.h @@ -91,6 +91,8 @@ extern const char *PLUGINNAME; if (ctx) bfuncs->DebugMessage ( ctx, __FILE__, __LINE__, level, "%s " msg, PLUGINPREFIX, var1, var2, var3, var4 ); #define DMSG6(ctx,level,msg,var1,var2,var3,var4,var5,var6) \ if (ctx) bfuncs->DebugMessage ( ctx, __FILE__, __LINE__, level, "%s " msg, PLUGINPREFIX, var1, var2, var3, var4, var5, var6 ); +#define DMSG7(ctx,level,msg,var1,var2,var3,var4,var5,var6,var7) \ + if (ctx) bfuncs->DebugMessage ( ctx, __FILE__, __LINE__, level, "%s " msg, PLUGINPREFIX, var1, var2, var3, var4, var5, var6, var7); /* fixed debug level definitions */ #define D1 1 /* debug for every error */