zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: Re: Aliasing assignment-ish words (aliases[x=y]=z)
Date: Wed, 13 Jan 2016 00:57:55 +0000	[thread overview]
Message-ID: <20160113005755.GA7091@tarsus.local2> (raw)
In-Reply-To: <160111234429.ZM6760@torch.brasslantern.com>

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.


  reply	other threads:[~2016-01-13  0:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-01  0:37 Daniel Shahaf
2016-01-10 19:19 ` Bart Schaefer
2016-01-10 19:50   ` Daniel Shahaf
2016-01-12  7:44     ` Bart Schaefer
2016-01-13  0:57       ` Daniel Shahaf [this message]
2016-01-13  0:58       ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160113005755.GA7091@tarsus.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).