zsh-workers
 help / color / mirror / code / Atom feed
* bug with %<< prompt expansion
@ 2014-09-26 23:27 Joel Elkins
  2014-09-27  4:39 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Joel Elkins @ 2014-09-26 23:27 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 362 bytes --]

Hello. I think there may be a bug in the truncation operator %>> in the
prompt expansion code. It seems to count a sequence surrounded by %{ %} as
having width = 1, as shown below.

% echo $ZSH_VERSION
5.0.6
% print -P "%4>.>12345"
123.
% print -P "%4>.>1%{%}2345"
12.

In my opinion, these two commands should have the same output.

Thanks,

-- 
Joel D. Elkins

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: bug with %<< prompt expansion
  2014-09-26 23:27 bug with %<< prompt expansion Joel Elkins
@ 2014-09-27  4:39 ` Bart Schaefer
  2014-09-28 13:40   ` Joel Elkins
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2014-09-27  4:39 UTC (permalink / raw)
  To: zsh-workers

On Sep 26,  6:27pm, Joel Elkins wrote:
}
} % print -P "%4>.>12345"
} 123.
} % print -P "%4>.>1%{%}2345"
} 12.
} 
} In my opinion, these two commands should have the same output.

Right you are.  I'm not entirely sure why this doesn't seem to affect
%<< but it looks like it has the same logic error, so I patched that
branch as well.


diff --git a/Src/prompt.c b/Src/prompt.c
index 9ed6c54..0cc9ef9 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -1316,12 +1316,11 @@ prompttrunc(int arg, int truncchar, int doprint, int endchar,
 			     */
 			    for (;;) {
 				*ptr++ = *fulltextptr;
-				if (*fulltextptr == Outpar ||
-				    *fulltextptr == '\0')
+				if (*fulltextptr == '\0' ||
+				    *fulltextptr++ == Outpar)
 				    break;
-				if (*fulltextptr == Nularg)
+				if (fulltextptr[-1] == Nularg)
 				    remw--;
-				fulltextptr++;
 			    }
 			} else {
 #ifdef MULTIBYTE_SUPPORT
@@ -1397,12 +1396,11 @@ prompttrunc(int arg, int truncchar, int doprint, int endchar,
 			if (*skiptext == Inpar) {
 			    /* see comment on left truncation above */
 			    for (;;) {
-				if (*skiptext == Outpar ||
-				    *skiptext == '\0')
+				if (*skiptext == '\0' ||
+				    *skiptext++ == Outpar)
 				    break;
-				if (*skiptext == Nularg)
+				if (skiptext[-1] == Nularg)
 				    maxwidth--;
-				skiptext++;
 			    }
 			} else {
 #ifdef MULTIBYTE_SUPPORT


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: bug with %<< prompt expansion
  2014-09-27  4:39 ` Bart Schaefer
@ 2014-09-28 13:40   ` Joel Elkins
  0 siblings, 0 replies; 3+ messages in thread
From: Joel Elkins @ 2014-09-28 13:40 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 2352 bytes --]

I tested this patch and can confirm it fixes the issues on my end.

Thanks,
Joel

On Fri, Sep 26, 2014 at 11:39 PM, Bart Schaefer <schaefer@brasslantern.com>
wrote:

> On Sep 26,  6:27pm, Joel Elkins wrote:
> }
> } % print -P "%4>.>12345"
> } 123.
> } % print -P "%4>.>1%{%}2345"
> } 12.
> }
> } In my opinion, these two commands should have the same output.
>
> Right you are.  I'm not entirely sure why this doesn't seem to affect
> %<< but it looks like it has the same logic error, so I patched that
> branch as well.
>
>
> diff --git a/Src/prompt.c b/Src/prompt.c
> index 9ed6c54..0cc9ef9 100644
> --- a/Src/prompt.c
> +++ b/Src/prompt.c
> @@ -1316,12 +1316,11 @@ prompttrunc(int arg, int truncchar, int doprint,
> int endchar,
>                              */
>                             for (;;) {
>                                 *ptr++ = *fulltextptr;
> -                               if (*fulltextptr == Outpar ||
> -                                   *fulltextptr == '\0')
> +                               if (*fulltextptr == '\0' ||
> +                                   *fulltextptr++ == Outpar)
>                                     break;
> -                               if (*fulltextptr == Nularg)
> +                               if (fulltextptr[-1] == Nularg)
>                                     remw--;
> -                               fulltextptr++;
>                             }
>                         } else {
>  #ifdef MULTIBYTE_SUPPORT
> @@ -1397,12 +1396,11 @@ prompttrunc(int arg, int truncchar, int doprint,
> int endchar,
>                         if (*skiptext == Inpar) {
>                             /* see comment on left truncation above */
>                             for (;;) {
> -                               if (*skiptext == Outpar ||
> -                                   *skiptext == '\0')
> +                               if (*skiptext == '\0' ||
> +                                   *skiptext++ == Outpar)
>                                     break;
> -                               if (*skiptext == Nularg)
> +                               if (skiptext[-1] == Nularg)
>                                     maxwidth--;
> -                               skiptext++;
>                             }
>                         } else {
>  #ifdef MULTIBYTE_SUPPORT
>



-- 
Joel D. Elkins

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-09-28 13:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-26 23:27 bug with %<< prompt expansion Joel Elkins
2014-09-27  4:39 ` Bart Schaefer
2014-09-28 13:40   ` Joel Elkins

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).