about summary refs log tree commit diff
path: root/posix
diff options
context:
space:
mode:
Diffstat (limited to 'posix')
-rw-r--r--posix/wordexp-test.c7
-rw-r--r--posix/wordexp.c30
2 files changed, 18 insertions, 19 deletions
diff --git a/posix/wordexp-test.c b/posix/wordexp-test.c
index 82af1666a2..d73021cc2e 100644
--- a/posix/wordexp-test.c
+++ b/posix/wordexp-test.c
@@ -119,6 +119,11 @@ struct test_case_struct
     { 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 @@ struct test_case_struct
     { 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 },
diff --git a/posix/wordexp.c b/posix/wordexp.c
index fe3e2b2cea..dff5d30dad 100644
--- a/posix/wordexp.c
+++ b/posix/wordexp.c
@@ -2049,8 +2049,8 @@ wordexp (const char *words, wordexp_t *pwordexp, int flags)
   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 @@ wordexp (const char *words, wordexp_t *pwordexp, int flags)
   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 @@ wordexp (const char *words, wordexp_t *pwordexp, int flags)
 	/* 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,