zsh-workers
 help / color / mirror / code / Atom feed
* vcs_info: '%' in payloads not escaped
@ 2016-12-27 15:05 Daniel Shahaf
  2016-12-27 15:13 ` Daniel Shahaf
  2017-01-05 16:07 ` Daniel Shahaf
  0 siblings, 2 replies; 14+ messages in thread
From: Daniel Shahaf @ 2016-12-27 15:05 UTC (permalink / raw)
  To: zsh-workers

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]}
]]]


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

end of thread, other threads:[~2017-02-07  9:01 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-27 15:05 vcs_info: '%' in payloads not escaped Daniel Shahaf
2016-12-27 15:13 ` Daniel Shahaf
2017-01-05 16:07 ` Daniel Shahaf
2017-01-05 16:27   ` Frank Terbeck
2017-01-06  2:21     ` Daniel Shahaf
2017-01-06 10:41       ` Frank Terbeck
2017-01-06 16:40         ` Daniel Shahaf
2017-01-06 17:27           ` Bart Schaefer
2017-01-23 11:04             ` Daniel Shahaf
2017-01-23 18:54               ` Frank Terbeck
2017-02-05  8:28                 ` [PATCH] vcs_info: Escape '%' signs in payloads Daniel Shahaf
2017-02-07  8:57                   ` Daniel Shahaf
2017-01-06 15:55   ` vcs_info: '%' in payloads not escaped Bart Schaefer
2017-01-06 16:49     ` 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).