summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2022-04-28 12:48:09 -0700
committerKevin McCarthy <kevin@8t8.us>2022-04-30 10:53:54 -0700
commita20ed9b4cfc3c9ec5dce3abbc502127bca6ce949 (patch)
tree0b51c51052bc0aaf42307d2badb19b1d0e656ace
parentb69aed8e322ec4f6351126756dce3206d942b7e1 (diff)
When expanding local paths, normalize to remove a trailing '/'.
Commit 986e9e74 normalized Maildir/mh paths upon opening, to aid in mailbox comparison issues that can crop up (as the IMAP path normalization does). Unfortunately, this caused other problems in cases where users were explicitly adding a trailing '/' to their config settings, such as with buffy mailboxes, or with $spoolfile. To normalize properly, we need to do as the IMAP code does - both on the context opening, and expand_path (as imap_expand_path() and imap_fix_path() do). This also helps other cases; for example, the file browser returns entries without a trailing '/', while tab completion in the editor menu appends a trailing '/'. Right now the only regression I'm aware of is with $header_cache on first use, which I will document in the next commit. If it turns out there are more important regressions I may have to back this and the original commit out.
-rw-r--r--muttlib.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/muttlib.c b/muttlib.c
index 47e64990..542ec7a9 100644
--- a/muttlib.c
+++ b/muttlib.c
@@ -649,17 +649,30 @@ void _mutt_buffer_expand_path (BUFFER *src, int rx, int expand_relative)
else
#endif
if (expand_relative &&
- (url_check_scheme (mutt_b2s (src)) == U_UNKNOWN) &&
- mutt_buffer_len (src) &&
- *mutt_b2s (src) != '/')
+ (url_check_scheme (mutt_b2s (src)) == U_UNKNOWN))
{
- if (mutt_getcwd (tmp))
+ if (mutt_buffer_len (src) &&
+ *mutt_b2s (src) != '/')
{
- /* Note, mutt_pretty_mailbox() does '..' and '.' handling. */
- if (mutt_buffer_len (tmp) > 1)
- mutt_buffer_addch (tmp, '/');
- mutt_buffer_addstr (tmp, mutt_b2s (src));
- mutt_buffer_strcpy (src, mutt_b2s (tmp));
+ if (mutt_getcwd (tmp))
+ {
+ /* Note, mutt_pretty_mailbox() does '..' and '.' handling. */
+ if (mutt_buffer_len (tmp) > 1)
+ mutt_buffer_addch (tmp, '/');
+ mutt_buffer_addstr (tmp, mutt_b2s (src));
+ mutt_buffer_strcpy (src, mutt_b2s (tmp));
+ }
+ }
+
+ /* Normalize paths to not end in a trailing '/', to make
+ * string comparisons more reliable. Note we only do this when
+ * expand_relative is set - other cases can include DT_CMD_PATH,
+ * which can have arbitrary "non-path" arguments after the path!
+ */
+ while ((mutt_buffer_len (src) > 1) &&
+ *(src->dptr - 1) == '/')
+ {
+ *(--src->dptr) = '\0';
}
}