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

vcs_info: '%' in payloads not escaped



To reproduce:

[[[
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.  Is the following correct?

[[[
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr b/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr
index e8c8e81..e9180b0 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr
@@ -100,7 +100,7 @@ rrn=${bzrbase:t}
 zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat bzrbr || bzrbr="%b:%r"
 hook_com=( branch "${bzrinfo[2]}" revision "${bzrinfo[1]}" )
 if VCS_INFO_hook 'set-branch-format' "${bzrbr}"; then
-    zformat -f bzrbr "${bzrbr}" "b:${hook_com[branch]}" "r:${hook_com[revision]}"
+    zformat -f bzrbr "${bzrbr}" "b:${hook_com[branch]//'%'/%%}" "r:${hook_com[revision]}"
 else
     bzrbr=${hook_com[branch-replace]}
 fi
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index 4ec87c6..6272f69 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -149,7 +149,7 @@ VCS_INFO_git_handle_patches () {
     hook_com=( applied "${git_applied_s}"     unapplied "${git_patches_unapplied}"
                applied-n ${#git_patches_applied} unapplied-n ${#git_patches_unapplied} all-n ${git_all} )
     if VCS_INFO_hook 'set-patch-format' "${gitmsg}"; then
-        zformat -f gitmisc "${gitmsg}" "p:${hook_com[applied]}" "u:${hook_com[unapplied]}" \
+        zformat -f gitmisc "${gitmsg}" "p:${hook_com[applied]//'%'/%%}" "u:${hook_com[unapplied]//'%'/%%}" \
                                           "n:${#git_patches_applied}" "c:${#git_patches_unapplied}" "a:${git_all}"
     else
         gitmisc=${hook_com[patch-replace]}
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
index 69b7db3..8c902a7 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
@@ -113,7 +113,7 @@ hook_com=( branch "${r_branch}" revision "${r_lrev}" )
 
 if VCS_INFO_hook 'set-branch-format' "${branchformat}"; then
     zformat -f branchformat "${branchformat}" \
-        "b:${hook_com[branch]}" "r:${hook_com[revision]}"
+        "b:${hook_com[branch]//'%'/%%}" "r:${hook_com[revision]}"
 else
     branchformat=${hook_com[branch-replace]}
 fi
@@ -239,9 +239,9 @@ if zstyle -T ":vcs_info:${vcs}:${usercontext}:${rrn}" get-mq \
 
     if VCS_INFO_hook 'set-patch-format' ${qstring}; then
         zformat -f hgmqstring "${hgmqstring}" \
-            "p:${hook_com[applied]}" "u:${hook_com[unapplied]}" \
+            "p:${hook_com[applied]//'%'/%%}" "u:${hook_com[unapplied]//'%'/%%}" \
             "n:${#mqpatches}" "c:${#mqunapplied}" "a:${#mqseries}" \
-            "g:${hook_com[guards]}" "G:${#mqguards}"
+            "g:${hook_com[guards]//'%'/%%}" "G:${#mqguards}"
     else
         hgmqstring=${hook_com[patch-replace]}
     fi
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4 b/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4
index 3298849..c23f4f3 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4
@@ -20,7 +20,7 @@ change="${${$(${vcs_comm[cmd]} changes -m 1 ...\#have)##Change }%% *}"
 zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat p4branch || p4branch="%b:%r"
 hook_com=( branch "${p4info[Client_name]}" revision "${change}" )
 if VCS_INFO_hook 'set-branch-format' "${p4branch}"; then
-    zformat -f p4branch "${p4branch}" "b:${hook_com[branch]}" "r:${hook_com[revision]}"
+    zformat -f p4branch "${p4branch}" "b:${hook_com[branch]//'%'/%%}" "r:${hook_com[revision]}"
 else
     p4branch=${hook_com[branch-replace]}
 fi
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
index e1334f6..19affbd 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
@@ -52,7 +52,7 @@ rrn=${svnbase:t}
 zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat svnbranch || svnbranch="%b:%r"
 hook_com=( branch "${svninfo[URL]##*/}" revision "${cwdinfo[Revision]}" )
 if VCS_INFO_hook 'set-branch-format' "${svnbranch}"; then
-    zformat -f svnbranch "${svnbranch}" "b:${hook_com[branch]}" "r:${hook_com[revision]}"
+    zformat -f svnbranch "${svnbranch}" "b:${hook_com[branch]//'%'/%%}" "r:${hook_com[revision]}"
 else
     svnbranch=${hook_com[branch-replace]}
 fi
diff --git a/Functions/VCS_Info/VCS_INFO_quilt b/Functions/VCS_Info/VCS_INFO_quilt
index 4c61506..a39cd1a 100644
--- a/Functions/VCS_Info/VCS_INFO_quilt
+++ b/Functions/VCS_Info/VCS_INFO_quilt
@@ -197,7 +197,7 @@ function VCS_INFO_quilt() {
     hook_com=( applied "${applied_string}" unapplied "${unapplied_string}"
                applied-n ${#applied}       unapplied-n ${#unapplied}       all-n ${#all} )
     if VCS_INFO_hook 'set-patch-format' ${qstring}; then
-        zformat -f qstring "${qstring}" "p:${hook_com[applied]}" "u:${hook_com[unapplied]}" \
+        zformat -f qstring "${qstring}" "p:${hook_com[applied]//'%'/%%}" "u:${hook_com[unapplied]//'%'/%%}" \
                                         "n:${#applied}" "c:${#unapplied}" "a:${#all}"
     else
         qstring=${hook_com[patch-replace]}
]]]



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