From d0e3a85d09eb43c5de821dded7fc4aa76f593d2d Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 7 May 2021 18:27:17 -0400 Subject: Testing (#5) * Fix separators appearing at the end once and for all * Add cleanpath executable tests * Escape slashes * Enable verbose testing --- lib/cleanpath.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/cleanpath.c b/lib/cleanpath.c index fdb615d..c3a7e81 100644 --- a/lib/cleanpath.c +++ b/lib/cleanpath.c @@ -103,6 +103,7 @@ void cleanpath_filter(struct CleanPath *path, unsigned mode, const char *pattern */ char *cleanpath_read(struct CleanPath *path) { char *result; + size_t result_len; result = calloc(path->data_len, sizeof(char)); if (result == NULL) { @@ -115,11 +116,12 @@ char *cleanpath_read(struct CleanPath *path) { continue; } strcat(result, path->part[i]); + strcat(result, path->sep); + } - // Do not append path separator on final element - if (path->part[i + 1] != NULL && *path->part[i + 1] != '\0') { - strcat(result, path->sep); - } + result_len = strlen(result); + if (result_len) { + result[result_len - 1] = '\0'; } cleanpath_read__failure: -- cgit