From: Kevin McCarthy Date: Sat, 20 Apr 2019 19:34:35 +0000 (-0700) Subject: Convert compress to use mutt_buffer_quote_filename(). X-Git-Tag: mutt-1-12-rel~47 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=20bedeace08c699280cfa38582fdadf42ef8e701;p=mutt Convert compress to use mutt_buffer_quote_filename(). Because the compress expandos operate differently than the rest of mutt, requiring manual outer quoting, add a parameter to the function to toggle outer quoting off. Remove the now unused escape_path() function. --- diff --git a/compress.c b/compress.c index 7e6ba75c..2d600e0f 100644 --- a/compress.c +++ b/compress.c @@ -295,49 +295,6 @@ mutt_free_compress_info (CONTEXT *ctx) FREE (&ctx->compress_info); } -/** - * escape_path - Escapes single quotes in a path for a command string. - * @src - the path to escape. - * - * Returns: a pointer to the escaped string. - */ -static char * -escape_path (char *src) -{ - static char dest[HUGE_STRING]; - char *destp = dest; - int destsize = 0; - - if (!src) - return NULL; - - while (*src && (destsize < sizeof(dest) - 1)) - { - if (*src != '\'') - { - *destp++ = *src++; - destsize++; - } - else - { - /* convert ' into '\'' */ - if (destsize + 4 < sizeof(dest)) - { - *destp++ = *src++; - *destp++ = '\\'; - *destp++ = '\''; - *destp++ = '\''; - destsize += 4; - } - else - break; - } - } - *destp = '\0'; - - return dest; -} - /** * cb_format_str - Expand the filenames in the command string * @dest: Buffer in which to save string @@ -362,22 +319,33 @@ cb_format_str (char *dest, size_t destlen, size_t col, int cols, char op, const const char *fmt, const char *ifstring, const char *elsestring, unsigned long data, format_flag flags) { + CONTEXT *ctx = (CONTEXT *) data; + BUFFER *quoted = NULL; + if (!dest || (data == 0)) return src; - CONTEXT *ctx = (CONTEXT *) data; + /* NOTE the compressed file config vars expect %f and %t to be + * surrounded by '' (unlike other Mutt config vars, which add the + * outer quotes for the user). This is why we use the + * _mutt_buffer_quote_filename() form with add_outer of 0. */ + quoted = mutt_buffer_pool_get (); switch (op) { case 'f': /* Compressed file */ - snprintf (dest, destlen, "%s", NONULL (escape_path (ctx->realpath))); + _mutt_buffer_quote_filename (quoted, ctx->realpath, 0); + snprintf (dest, destlen, "%s", mutt_b2s (quoted)); break; case 't': /* Plaintext, temporary file */ - snprintf (dest, destlen, "%s", NONULL (escape_path (ctx->path))); + _mutt_buffer_quote_filename (quoted, ctx->path, 0); + snprintf (dest, destlen, "%s", mutt_b2s (quoted)); break; } + + mutt_buffer_pool_release ("ed); return src; } diff --git a/muttlib.c b/muttlib.c index 45888169..39b9e8d5 100644 --- a/muttlib.c +++ b/muttlib.c @@ -1003,14 +1003,15 @@ void mutt_pretty_size (char *s, size_t len, LOFF_T n) } } -void mutt_buffer_quote_filename (BUFFER *d, const char *f) +void _mutt_buffer_quote_filename (BUFFER *d, const char *f, int add_outer) { mutt_buffer_clear (d); if (!f) return; - mutt_buffer_addch (d, '\''); + if (add_outer) + mutt_buffer_addch (d, '\''); for (; *f; f++) { @@ -1025,7 +1026,8 @@ void mutt_buffer_quote_filename (BUFFER *d, const char *f) mutt_buffer_addch (d, *f); } - mutt_buffer_addch (d, '\''); + if (add_outer) + mutt_buffer_addch (d, '\''); } static const char safe_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+@{}._-:%/"; diff --git a/protos.h b/protos.h index c9b8d5c8..14e32f41 100644 --- a/protos.h +++ b/protos.h @@ -172,7 +172,8 @@ int mutt_bounce_message (FILE *fp, HEADER *, ADDRESS *); void mutt_break_thread (HEADER *); void mutt_browser_cleanup (void); void mutt_buffer_concat_path (BUFFER *, const char *, const char *); -void mutt_buffer_quote_filename (BUFFER *, const char *); +#define mutt_buffer_quote_filename(a,b) _mutt_buffer_quote_filename (a, b, 1); +void _mutt_buffer_quote_filename (BUFFER *, const char *, int); void mutt_buffer_sanitize_filename (BUFFER *d, const char *f, short slash); void mutt_canonical_charset (char *, size_t, const char *); void mutt_check_stats(void);