]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Strip leading/ending spaces in plugutil_str_split_to_alist()
authorEric Bollengier <eric@baculasystems.com>
Fri, 11 Feb 2022 09:28:16 +0000 (10:28 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:57 +0000 (13:56 +0200)
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.

bacula/src/plugins/fd/pluginlib/pluginlib.cpp
bacula/src/plugins/fd/pluginlib/pluginlib.h

index cb9087962fa6f1e215f06d529ce40659b815aa83..7ad0cd0c876ca8f3e49f2f84ec967a7f0c5275f7 100644 (file)
@@ -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);
index cbb89e9e7e79e9e2d480f97afd930e5faa810728..fdd6f4214c3f57fa81700dbca5840385c4619558 100644 (file)
@@ -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 */