Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: vcs_info: '%' in payloads not escaped



Daniel Shahaf wrote on Tue, Dec 27, 2016 at 15:05:07 +0000:
> [[[
> autoload vcs_info
> vcs_info
> precmd () {
>         vcs_info
> 	print -Plr -- ${vcs_info_msg_0_} ${vcs_info_msg_1_}
> }
> zstyle ':vcs_info:*' formats ' (%s)-[%b]%u%c-' %m
> zstyle ':vcs_info:*' actionformats ' (%s)-[%b|%a]%u%c-' %m
> 
> cd "$(mktemp -d)"
> git init
> echo foo > foo
> git add foo
> git commit -am import > /dev/null
> git branch br
> echo foo2 >> foo
> git commit -am "left"
> git checkout br
> echo foo2b >> foo
> git commit -am "%F{red} right"
> git checkout --detach
> git rebase master
> ]]]
> 
> At the end of the script, $vcs_info_msg_1_ is printed as
> "6c0df9e1f8ebcdbeb94b08d906e068086ec76709  right (1 applied)"
> with the "right (1 applied)" part in red.
> 
> This also happens after «hg branch "%F{red} foo"», etc..
> 
> I work around this hook by doing ${1//'%'/%%} in my gen-applied-string
> hook.  I assume vcs_info itself should be doing that, but I'm not sure
> where in the code to add that.

How about the following?

[[[
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index 63109aa..84382ad 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -131,12 +131,14 @@ VCS_INFO_git_handle_patches () {
         else
             git_applied_s=""
         fi
+        git_applied_s=${git_applied_s//'%'/%%}
     else
         git_applied_s=${hook_com[applied-string]}
     fi
     hook_com=()
     if VCS_INFO_hook 'gen-unapplied-string' "${git_patches_unapplied[@]}"; then
         git_patches_unapplied=${#git_patches_unapplied}
+        git_patches_unapplied=${git_patches_unapplied//'%'/%%}
     else
         git_patches_unapplied=${hook_com[unapplied-string]}
     fi
]]]

This adds % escaping only when the hook was not called.

If this is correct then similar changes would be needed to the quilt,
hg, and other codepaths that suffer from the same problem, 

Escaping % signs in 'git_patches_unapplied' is just for future-proofing,
in case the immediately preceding line changes.

Cheers,

Daniel
[for the archives: some additional discussion about this issue occured
in users/22321]



Messages sorted by: Reverse Date, Date, Thread, Author