diff mbox series

alias: Fix handling of empty aliases

Message ID m2y33ftyu7.fsf@pomona.edu (mailing list archive)
State Superseded
Delegated to: Herbert Xu
Headers show
Series alias: Fix handling of empty aliases | expand

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>

Comments

Martijn Dekker April 27, 2020, 8:31 p.m. UTC | #1
Op 09-05-19 om 16:46 schreef Michael Greenberg:
> Dash was incorrectly handling empty aliases.

For the record, the behaviour in Busybox ash, FreeBSD sh and NetBSD sh 
is the same.

- M.
diff mbox series

Patch

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: