Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Aliasing assignment-ish words (aliases[x=y]=z)



Bart Schaefer wrote on Mon, Jan 11, 2016 at 23:44:29 -0800:
> On Jan 10,  7:50pm, Daniel Shahaf wrote:
> } I thought we might want to have 'alias -L' handle LHSes with '=' in them
> } specially: omit them from the output with a warning, or maybe fail hard
> 
> Yeah, that probably wouldn't be too difficult (I'd go with the warning).
> 

Okay.

diff --git a/Src/hashtable.c b/Src/hashtable.c
index 2d1ff87..0664c36 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 3896178..cfa9dae 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.



Messages sorted by: Reverse Date, Date, Thread, Author