From cbaff216b3eca57b4fd717da53f43a6713722e95 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 29 Jul 2011 18:49:38 -0500 Subject: Don't trim whitespace when reading database entries We don't write with extra or unknown whitespace, so there is little reason for us to trim it when reading either. This also fixes the hopefully never encountered "paths that start or end with spaces" issue, for which two pactests have been added. The tests also contain other evil characters that we have encountered before and handle just fine, but it doesn't hurt to ensure we don't break such support in the future. Signed-off-by: Dan McGee --- lib/libalpm/util.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lib/libalpm/util.c') diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 030cf43b..123cd24e 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -207,6 +207,26 @@ char *_alpm_strtrim(char *str) return str; } +/** + * Trim trailing newline from a string (if one exists). + * @param str a single line of text + * @return the length of the trimmed string + */ +size_t _alpm_strip_newline(char *str) +{ + size_t len; + if(str == '\0') { + return 0; + } + len = strlen(str); + while(str[len - 1] == '\n') { + len--; + } + str[len] = '\0'; + + return len; +} + /* Compression functions */ /** -- cgit v1.2.3-24-g4f1b