alias: Fix handling of empty aliases
diff mbox series

Message ID m2y33ftyu7.fsf@pomona.edu
State Under Review
Delegated to: Herbert Xu
Headers show
Series
  • alias: Fix handling of empty aliases
Related show

Commit Message

Michael Greenberg May 9, 2019, 3:46 p.m. UTC
Dash was incorrectly handling empty aliases. When attempting to use an
empty alias with nothing else, I'm (incorrectly) prompted for more
input:

```
$ alias empty=''
$ empty
>
```

Other shells (e.g., bash, yash) correctly handle the lone, empty alias as an
empty command:

```
$ alias empty=''
$ empty
$
```

This patch fixes the parser to handle the case where an alias is empty,
i.e., produces no token.

Signed-off-by: Michael Greenberg <michael.greenberg@pomona.edu>

Patch
diff mbox series

diff --git a/src/parser.c b/src/parser.c
index 1f9e8ec..a1d6116 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -470,6 +470,7 @@  next_case:
 		break;
 	case TWORD:
 	case TREDIR:
+	case TNL: /* necessary for empty aliases */
 		tokpushback++;
 		return simplecmd();
 	}
@@ -717,6 +718,7 @@  top:
 		}
 	}
 
+ignorenl: /* empty alias? */
 	if (t != TWORD || quoteflag) {
 		goto out;
 	}
@@ -739,8 +741,11 @@  top:
 		if ((ap = lookupalias(wordtext, 1)) != NULL) {
 			if (*ap->val) {
 				pushstring(ap->val, ap);
+				goto top;
+			} else {
+				t = xxreadtoken();
+				goto ignorenl;
 			}
-			goto top;
 		}
 	}
 out: