]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Fix handling of empty string.
authorBruno Haible <bruno@clisp.org>
Mon, 31 Mar 2003 20:19:41 +0000 (20:19 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:10:19 +0000 (12:10 +0200)
gettext-tools/lib/ChangeLog
gettext-tools/lib/sh-quote.c

index 15f1a97e6750ceb1ccdabdf2b00c62b245292764..c577ae40c11ba85d2257cef4aea151bcd7609a31 100644 (file)
@@ -1,3 +1,8 @@
+2003-03-31  Bruno Haible  <bruno@clisp.org>
+
+       * sh-quote.c (shell_quote_length, shell_quote_copy): Handle empty
+       argument string correctly.
+
 2003-03-30  Bruno Haible  <bruno@clisp.org>
 
        * progname.c (ISSLASH, HAS_DEVICE, IS_PATH_WITH_DIR,
index 41c82c3bbc271a41be6d99399492071b3c987d21..4052aba1da62ea9f27bb9f6035a7650c36d16bbe 100644 (file)
@@ -1,5 +1,5 @@
 /* Shell quoting.
-   Copyright (C) 2001-2002 Free Software Foundation, Inc.
+   Copyright (C) 2001-2003 Free Software Foundation, Inc.
    Written by Bruno Haible <haible@clisp.cons.org>, 2001.
 
    This program is free software; you can redistribute it and/or modify
 #include "xmalloc.h"
 
 
+/* Must quote the program name and arguments since Unix shells interpret
+   characters like " ", "'", "<", ">", "$" etc. in a special way.  This
+   kind of quoting should work unless the string contains "\n" and we call
+   csh.  But we are lucky: only /bin/sh will be used.  */
+
 #define SHELL_SPECIAL_CHARS "\t\n !\"#$&'()*;<=>?[\\]`{|}~"
 
 /* Returns the number of bytes needed for the quoted string.  */
 size_t
 shell_quote_length (const char *string)
 {
-  if (strpbrk (string, SHELL_SPECIAL_CHARS) == NULL)
+  if (string[0] == '\0')
+    return 2;
+  else if (strpbrk (string, SHELL_SPECIAL_CHARS) == NULL)
     return strlen (string);
   else
     {
@@ -67,7 +74,12 @@ shell_quote_length (const char *string)
 char *
 shell_quote_copy (char *p, const char *string)
 {
-  if (strpbrk (string, SHELL_SPECIAL_CHARS) == NULL)
+  if (string[0] == '\0')
+    {
+      memcpy (p, "''", 2);
+      return p + 2;
+    }
+  else if (strpbrk (string, SHELL_SPECIAL_CHARS) == NULL)
     {
       memcpy (p, string, strlen (string));
       return p + strlen (string);