about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2016-01-13 00:57:55 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2016-01-13 01:25:46 +0000
commita8a00be442370ce491f9cc22a3fa0b4853feecb5 (patch)
tree798f6798171815349898ecc8811b57c6345b8295
parent152875ba03797e788397be7a3af6c09391dce9f0 (diff)
downloadzsh-a8a00be442370ce491f9cc22a3fa0b4853feecb5.tar.gz
zsh-a8a00be442370ce491f9cc22a3fa0b4853feecb5.tar.xz
zsh-a8a00be442370ce491f9cc22a3fa0b4853feecb5.zip
37591: 'alias -L': skip with a warning aliases with '=' in their LHS
-rw-r--r--ChangeLog3
-rw-r--r--Src/hashtable.c9
-rw-r--r--Test/A02alias.ztst8
3 files changed, 20 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 7309cb3f5..731e323ab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2016-01-13  Daniel Shahaf  <d.s@daniel.shahaf.name>
 
+	* 37591: Src/hashtable.c, Test/A02alias.ztst: 37591: 'alias -L':
+	skip with a warning aliases with '=' in their LHS
+
 	* 37550: Completion/BSD/Command/_cu: _cu: Support Linux
 	line-device names; fail gracefully on OSes matching no known
 	line-device name pattern.
diff --git a/Src/hashtable.c b/Src/hashtable.c
index 2d1ff87cb..0664c3694 100644
--- a/Src/hashtable.c
+++ b/Src/hashtable.c
@@ -1276,6 +1276,15 @@ printaliasnode(HashNode hn, int printflags)
     }
 
     if (printflags & PRINT_LIST) {
+	/* Fast fail on unrepresentable values. */
+	if (strchr(a->node.nam, '=')) {
+	    zwarn("invalid alias '%s' encountered while printing aliases", 
+		  a->node.nam);
+	    /* ### TODO: Return an error status to the C caller */
+	    return;
+	}
+
+	/* Normal path. */
 	printf("alias ");
 	if (a->node.flags & ALIAS_SUFFIX)
 	    printf("-s ");
diff --git a/Test/A02alias.ztst b/Test/A02alias.ztst
index 389617898..49e47567c 100644
--- a/Test/A02alias.ztst
+++ b/Test/A02alias.ztst
@@ -96,3 +96,11 @@
 0:unalias -as
 >foo is a suffix alias for print
 >foo: suffix alias
+
+  aliases[x=y]=z
+  alias -L | grep x=y
+  echo $pipestatus[1]
+0:printing invalid aliases warns
+>0
+?(eval):2: invalid alias 'x=y' encountered while printing aliases
+# Currently, 'alias -L' returns 0 in this case.  Perhaps it should return 1.