zsh-workers
 help / color / mirror / code / Atom feed
* [BUG] vcs_info - git branch with % in it's name
@ 2017-12-25  9:33 Doron Behar
  2017-12-25 20:17 ` Daniel Shahaf
  0 siblings, 1 reply; 3+ messages in thread
From: Doron Behar @ 2017-12-25  9:33 UTC (permalink / raw)
  To: zsh-workers

I think I found a bug within zsh's module vcs_info.

If a user is in a git repository with a '%' as part of the name of the
branch and he has '%b' in his prompt, he might get weird results, like:

 doron   bla9269ello  ~/repos/abcde 

Instead of:
 
 doron   bla%ello  ~/repos/abcde 
 
Has anyone encountered this before? I wonder why it happens..


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

* Re: [BUG] vcs_info - git branch with % in it's name
  2017-12-25  9:33 [BUG] vcs_info - git branch with % in it's name Doron Behar
@ 2017-12-25 20:17 ` Daniel Shahaf
  2017-12-30  8:56   ` Daniel Shahaf
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Shahaf @ 2017-12-25 20:17 UTC (permalink / raw)
  To: Doron Behar; +Cc: zsh-workers

Doron Behar wrote on Mon, 25 Dec 2017 11:33 +0200:
> I think I found a bug within zsh's module vcs_info.
> 
> If a user is in a git repository with a '%' as part of the name of the
> branch and he has '%b' in his prompt, he might get weird results, like:
> 
>  doron   bla9269ello  ~/repos/abcde 
> 
> Instead of:
>  
>  doron   bla%ello  ~/repos/abcde 
>  
> Has anyone encountered this before? I wonder why it happens..

Prompt expansions and zformat both use % as an expando introducer.  This is
basically the same form of bug as doing *«printf(argv[1])» in C.  %h is:

       %h
       %!     Current history event number.

(Incidentally, it is missing from «print -P %<TAB>» completion)

How about the following?  If that is the right fix then the adjacent lines will
need similar tweaking.

diff --git a/Functions/VCS_Info/VCS_INFO_formats b/Functions/VCS_Info/VCS_INFO_formats
index 4d0dd75c2..a46a10286 100644
--- a/Functions/VCS_Info/VCS_INFO_formats
+++ b/Functions/VCS_Info/VCS_INFO_formats
@@ -81,7 +81,7 @@ for i in {1..${#msgs}} ; do
     if VCS_INFO_hook "set-message" $(( $i - 1 )) "${msgs[$i]}"; then
         zformat -f msg ${msgs[$i]}                      \
                         a:${hook_com[action]}           \
-                        b:${hook_com[branch]}           \
+                        b:${hook_com[branch]//'%'/%%}   \
                         c:${hook_com[staged]}           \
                         i:${hook_com[revision]}         \
                         m:${hook_com[misc]}             \

Cheers,

Daniel


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

* Re: [BUG] vcs_info - git branch with % in it's name
  2017-12-25 20:17 ` Daniel Shahaf
@ 2017-12-30  8:56   ` Daniel Shahaf
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Shahaf @ 2017-12-30  8:56 UTC (permalink / raw)
  To: zsh-workers; +Cc: Doron Behar

Daniel Shahaf wrote on Mon, Dec 25, 2017 at 20:17:28 +0000:
> How about the following?  If that is the right fix then the adjacent lines will
> need similar tweaking.

That's not so straightforward.

Escaping the 'branch' value broke my post-backend hook, which was doing the
equivalent of «hook_com[branch]+="%f↑"».  That's fine; I wasn't expecting that
hack to work forever, and I can just change it to «…+=$(print -rP "%f↑")».  It
might warrant a NEWS/README entry, but otherwise, no sweat.

Next, if hook_com[staged] were escaped then settings such as «zstyle '*'
stagedstr '%Bthis is bold%b'» would stop working.  So, which hook_com keys
should be escaped and which shouldn't?  I don't see an easy way to tell.

> diff --git a/Functions/VCS_Info/VCS_INFO_formats b/Functions/VCS_Info/VCS_INFO_formats
> index 4d0dd75c2..a46a10286 100644
> --- a/Functions/VCS_Info/VCS_INFO_formats
> +++ b/Functions/VCS_Info/VCS_INFO_formats
> @@ -81,7 +81,7 @@ for i in {1..${#msgs}} ; do
>      if VCS_INFO_hook "set-message" $(( $i - 1 )) "${msgs[$i]}"; then
>          zformat -f msg ${msgs[$i]}                      \
>                          a:${hook_com[action]}           \
> -                        b:${hook_com[branch]}           \
> +                        b:${hook_com[branch]//'%'/%%}   \
>                          c:${hook_com[staged]}           \
>                          i:${hook_com[revision]}         \
>                          m:${hook_com[misc]}             \


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

end of thread, other threads:[~2017-12-30  8:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-25  9:33 [BUG] vcs_info - git branch with % in it's name Doron Behar
2017-12-25 20:17 ` Daniel Shahaf
2017-12-30  8:56   ` Daniel Shahaf

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