Updated patch attached. I think I addressed everything you mentioned.
Tests still pass.
$ ./mutt
Path 1 Path 2 Expected Result Derek's Version Status Old
Version Status
----------------------------------------------------------------------------------------
"foo/bar" "baz" foo/bar/baz "foo/bar/baz" PASS
"foo/bar/baz" PASS
"foo/bar/" "baz" foo/bar/baz "foo/bar/baz" PASS
"foo/bar/baz" PASS
"foo/bar/" "/baz" foo/bar/baz "foo/bar/baz" PASS
"foo/bar//baz" FAIL
"" "/baz" /baz "/baz" PASS "//baz"
FAIL
"/" "foo" /foo "/foo" PASS "/foo"
PASS
"/" "/foo" /foo "/foo" PASS "//foo"
FAIL
"foo/bar" "" foo/bar "foo/bar" PASS
"foo/bar" PASS
--
Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0xDFBEAD02
-=-=-=-=-
This message is posted from an invalid address. Replying to it will result in
undeliverable mail due to spam prevention. Sorry for the inconvenience.
diff --git a/muttlib.c b/muttlib.c
index 59a48378..d6636a3f 100644
--- a/muttlib.c
+++ b/muttlib.c
@@ -1389,12 +1389,37 @@ void mutt_safe_path(BUFFER *dest, ADDRESS *a)
void mutt_buffer_concat_path(BUFFER *d, const char *dir, const char *fname)
{
- const char *fmt = "%s/%s";
-
- if (!*fname || (*dir && dir[strlen(dir)-1] == '/'))
- fmt = "%s%s";
+ mutt_buffer_clear(d);
+ if (!*dir)
+ {
+ /* dir is empty, just append the file name */
+ mutt_buffer_addstr(d, fname);
+ }
+ else
+ {
+ /* dir is not empty, append it */
+ mutt_buffer_addstr(d, dir);
- mutt_buffer_printf(d, fmt, dir, fname);
+ /* Next, sort out appending the file name with or without a slash */
+ bool dir_ends_with_slash = dir[strlen(dir) - 1] == '/';
+ bool fname_starts_with_slash = *fname && fname[0] == '/';
+ /* if fname is nonempty, dir doesn't end with a slash, and fname doesn't
+ * start with a slash, append one */
+ if (!dir_ends_with_slash && *fname && !(fname_starts_with_slash))
+ {
+ mutt_buffer_addch(d, '/');
+ }
+ else if (dir_ends_with_slash && fname_starts_with_slash)
+ {
+ /* both have slashes; skip leading slashes of fname */
+ while (*fname && *fname == '/') fname++;
+ }
+ /* if fname is not empty, append it */
+ if (*fname)
+ {
+ mutt_buffer_addstr(d, fname);
+ }
+ }
}
/*