]> granicus.if.org Git - mutt/commitdiff
Convert compress to use mutt_buffer_quote_filename().
authorKevin McCarthy <kevin@8t8.us>
Sat, 20 Apr 2019 19:34:35 +0000 (12:34 -0700)
committerKevin McCarthy <kevin@8t8.us>
Sat, 20 Apr 2019 19:34:35 +0000 (12:34 -0700)
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.

compress.c
muttlib.c
protos.h

index 7e6ba75cac4f07645ab0677811d95f18b40dc70e..2d600e0ffb727c5fdf4dcf8e7d53060c2c3e8120 100644 (file)
@@ -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 (&quoted);
   return src;
 }
 
index 45888169a1f89e37bcbc7027c7391d5feb8c93f3..39b9e8d5c3664d70f6409143c2d2ff4ac737f28f 100644 (file)
--- 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+@{}._-:%/";
index c9b8d5c8b84590306317aa80eb61076d01f7a93f..14e32f4147ff1422a9837e4106e1503e64b93bfd 100644 (file)
--- 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);