summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3b22701)
raw | patch | inline | side by side (parent: 3b22701)
author | Florian Forster <octo@collectd.org> | |
Sun, 28 Jun 2015 12:05:05 +0000 (14:05 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Sun, 28 Jun 2015 12:05:05 +0000 (14:05 +0200) |
This also adds a unit test for this issue.
src/daemon/common.c | patch | blob | history | |
src/daemon/common_test.c | patch | blob | history |
diff --git a/src/daemon/common.c b/src/daemon/common.c
index dc6e4e1ed18452f17278b22ee72810e84bc268ea..9e0648cabaa94fdb3c38264410990a665cdad989 100644 (file)
--- a/src/daemon/common.c
+++ b/src/daemon/common.c
buffer_len--;
}
- for (i = 0; i < buffer_len - 1; i++)
+ for (i = 0; i < buffer_len; i++)
{
if (buffer[i] == '/')
buffer[i] = '_';
index f75621a612c6626fae28c8124b2cff4cd04fee08..ff33c9eb4794014e7c1bb662ea3260a8365127fb 100644 (file)
--- a/src/daemon/common_test.c
+++ b/src/daemon/common_test.c
return (0);
}
+DEF_TEST(escape_slashes)
+{
+ struct {
+ char *str;
+ char *want;
+ } cases[] = {
+ {"foo/bar/baz", "foo_bar_baz"},
+ {"/like/a/path", "like_a_path"},
+ {"trailing/slash/", "trailing_slash_"},
+ {"foo//bar", "foo__bar"},
+ };
+ size_t i;
+
+ for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) {
+ char buffer[32];
+
+ strncpy (buffer, cases[i].str, sizeof (buffer));
+ OK(escape_slashes (buffer, sizeof (buffer)) == 0);
+ STREQ(cases[i].want, buffer);
+ }
+
+ return 0;
+}
+
DEF_TEST(strunescape)
{
char buffer[16];
RUN_TEST(sstrdup);
RUN_TEST(strsplit);
RUN_TEST(strjoin);
+ RUN_TEST(escape_slashes);
RUN_TEST(strunescape);
RUN_TEST(parse_values);