Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Incorrect evaluation of ~ test in ternary conditional
- X-seq: zsh-workers 42136
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Felix Uhl <felix.uhl@xxxxxxxxxx>
- Subject: Re: Incorrect evaluation of ~ test in ternary conditional
- Date: Sat, 16 Dec 2017 14:01:05 -0800
- Cc: "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=1kyReb+zh0nY+OTDyrb5/VU3WnybREDOzfnRQNAlAC8=; b=a5sRGT/fKitiE65saRwOzhAICN7QcIg/qyOxNoJq9cRoHFianzxknoxcPmabHtk5Cc 6AKr1y6qF4R/L3nY0PNF1q8yg1evPuVBx2mIYlO+Ypuq2ObHOtxKVNGmz7/2qQDKFPt4 a/0hVDk0qj7ntXv/Fx1MNSRekAO8dXaJ6lgjr8N7qm1gPUxIW582UCBlpWOEcwpQXiDU yuRG+MdRVCjbCzdljZ9cADSacLyh2a8wfNhAvvb7KmJDE6dgOjnskhCr5elSdlc0jpBx tba/fg7RDfPLfpKM2Tm6zdaeDGHeBdhttbTYiBNZcw5c0ytcmAGl0ijjvm/wkJ3gKrjk PEHQ==
- In-reply-to: <DB6P194MB0037AE570D0106FB365F3C549D0B0@DB6P194MB0037.EURP194.PROD.OUTLOOK.COM>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <DB6P194MB0037AE570D0106FB365F3C549D0B0@DB6P194MB0037.EURP194.PROD.OUTLOOK.COM>
On Fri, Dec 15, 2017 at 5:55 AM, Felix Uhl <felix.uhl@xxxxxxxxxx> wrote:
> Hi everybody!
>
> Let there be a directory ~/work. Using the ~ test character in a
> conditional ternary prompt will return incorrect results when the
> argument is 2 as shown below:
>
> $ cd && print -P "%(2~:true:false)"
> false
> $ cd work/.. && print -P "%(2~:true:false)"
> true
I actually get randomly incorrect results in the FIRST of your examples:
repeat 5 do cd && print -P "%~ %(2~:true:false)" ; done
~ true
~ false
~ true
~ false
~ false
The second case is consistent but is always wrong:
repeat 5 do cd work/.. && print -P "%~ %(2~:true:false)" ; done
~ true
~ true
~ true
~ true
~ true
Both of the foregoing happen in each of 5.0.2 and the latest
development version. I don't have 5.0.5 handy.
This seems to be the fix:
diff --git a/Src/prompt.c b/Src/prompt.c
index c478e69..63e8093 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -315,7 +315,7 @@ putpromptchar(int doprint, int endchar, unsigned
int *txtchangep)
case '/':
case 'C':
/* `/' gives 0, `/any' gives 1, etc. */
- if (*ss++ == '/' && *ss)
+ if (*ss && *ss++ == '/' && *ss)
arg--;
for (; *ss; ss++)
if (*ss == '/')
I'm not sure whether (*ss == '/' && *++ss) would be equivalent, i.e.,
I don't know why the original formulation skips over the first
character whether or not it is a '/'. Possibly to skip a leading '~'?
Messages sorted by:
Reverse Date,
Date,
Thread,
Author