From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19824 invoked by alias); 13 Jan 2016 00:57:59 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 37591 Received: (qmail 12178 invoked from network); 13 Jan 2016 00:57:58 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 Date: Wed, 13 Jan 2016 00:57:55 +0000 From: Daniel Shahaf To: zsh-workers@zsh.org Subject: Re: Aliasing assignment-ish words (aliases[x=y]=z) Message-ID: <20160113005755.GA7091@tarsus.local2> References: <20160110003757.GA18461@tarsus.local2> <160110111943.ZM864@torch.brasslantern.com> <20160110195030.GB1997@tarsus.local2> <160111234429.ZM6760@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <160111234429.ZM6760@torch.brasslantern.com> User-Agent: Mutt/1.5.23 (2014-03-12) 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.