This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

wordexp IFS fixes


Hi,

I've fixed a couple of bugs in wordexp to do with IFS handling, and added
the relevant tests.

There's another case I'd like to add a test for, but I'm not quite sure
what the outcome should be!

If IFS=':', how many words would you expect ":abc:" to expand to?  
wordexp currently says 1 ("abc"), which is certainly wrong; bash seems to
say 2 ("" and "abc"), and the spec (or what I have of it) would seem to
say 3 ("", "abc", and "").  I expect that I've misread the spec..

Tim.
*/

Thu Sep  3 20:14:08 1998  Tim Waugh  <tim@cyberelk.demon.co.uk>

	* posix/wordexp-test.c: Add tests for different IFS values.
	Change unquoted-newline test so that newline is not in IFS.

	* posix/wordexp.c (wordexp): Correct null/unset mix-up when
	determining IFS characters.  Return WRDE_BADCHAR for unquoted
	special characters _except_ if they are separators.

--- libc/posix/wordexp.c	Mon Jul 20 22:47:07 1998
+++ /big/libc/posix/wordexp.c	Thu Sep  3 20:12:03 1998
@@ -2049,8 +2049,8 @@
   ifs = getenv ("IFS");
 
   if (!ifs)
-    /* NULL IFS means no field-splitting is to be performed */
-    ifs = strcpy (ifs_white, "");
+    /* IFS unset - use <space><tab><newline>. */
+    ifs = strcpy (ifs_white, " \t\n");
   else
     {
       char *ifsch = ifs;
@@ -2082,22 +2082,6 @@
   for (words_offset = 0 ; words[words_offset] ; ++words_offset)
     switch (words[words_offset])
       {
-      case '\n':
-      case '|':
-      case '&':
-      case ';':
-      case '<':
-      case '>':
-      case '(':
-      case ')':
-	case '{':
-      case '}':
-	/* Fail */
-	wordfree (pwordexp);
-	pwordexp->we_wordc = 0;
-	pwordexp->we_wordv = old_wordv;
-	return WRDE_BADCHAR;
-
       case '\\':
 	error = parse_backslash (&word, &word_length, &max_length, words,
 				 &words_offset);
@@ -2175,6 +2159,16 @@
 	/* Is it a field separator? */
 	if (strchr (ifs, words[words_offset]) == NULL)
 	  {
+	    /* Not a field separator -- but is it a valid word char? */
+	    if (strchr ("\n|&;<>(){}", words[words_offset]))
+	      {
+		/* Fail */
+		wordfree (pwordexp);
+		pwordexp->we_wordc = 0;
+		pwordexp->we_wordv = old_wordv;
+		return WRDE_BADCHAR;
+	      }
+
 	    /* "Ordinary" character -- add it to word */
 
 	    word = w_addchar (word, &word_length, &max_length,
--- libc/posix/wordexp-test.c	Mon Jul 20 23:16:20 1998
+++ /big/libc/posix/wordexp-test.c	Thu Sep  3 20:11:50 1998
@@ -119,6 +119,11 @@
     { 0, "foo", "*$var*", 0, 1, { "*foo*", }, IFS },
     { 0, "o thr", "*$var*", 0, 2, { "two", "three" }, IFS },
 
+    /* Different IFS values */
+    { 0, NULL, "a b\tc\nd  ", 0, 4, { "a", "b", "c", "d" }, NULL /* unset */ },
+    { 0, NULL, "a b\tc d  ", 0, 1, { "a b\tc d  " }, "" /* `null' */ },
+    { 0, NULL, "a,b c\n, d", 0, 3, { "a", "b c", " d" }, "\t\n," },
+
     /* Other things that should succeed */
     { 0, NULL, "\\*\"|&;<>\"\\(\\)\\{\\}", 0, 1, { "*|&;<>(){}", }, IFS },
     { 0, "???", "$var", 0, 1, { "???", }, IFS },
@@ -127,7 +132,7 @@
     { 0, NULL, "", 0, 0, { NULL, }, IFS },
 
     /* Things that should fail */
-    { WRDE_BADCHAR, NULL, "new\nline", 0, 0, { NULL, }, IFS },
+    { WRDE_BADCHAR, NULL, "new\nline", 0, 0, { NULL, }, "" /* \n not IFS */ },
     { WRDE_BADCHAR, NULL, "pipe|symbol", 0, 0, { NULL, }, IFS },
     { WRDE_BADCHAR, NULL, "&ampersand", 0, 0, { NULL, }, IFS },
     { WRDE_BADCHAR, NULL, "semi;colon", 0, 0, { NULL, }, IFS },



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]