From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20133 invoked by alias); 5 Feb 2017 08:32:40 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 40492 Received: (qmail 18502 invoked from network); 5 Feb 2017 08:32:40 -0000 X-Qmail-Scanner-Diagnostics: from out1-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(66.111.4.25):SA:0(-0.7/5.0):. Processed in 2.649571 secs); 05 Feb 2017 08:32:40 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=8vBEIeV1Dcvc0Z6C4340CJFYM8A=; b=fD5+9t EFc3WuFKZkmvkd8A3GnY9QKCf5asgzatfSLvMQqVSv6Q/yrf6Mf4zGyMDpLxV+4i IsNH56nlmTE9l9mdyGg9lBQV0qOvb30V9wc2qNdKC4BK1AzyP5cXYXdOwAe4hTsm eXeIsZLfm3mw2/U6FHC4gIcHVV9BeDX2jfINs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=smtpout; bh=8vBEIeV1Dcvc0Z6C4340CJFYM8A=; b=JfvuF f7mHgl2nK6mp/+z5LjXxjApFUb0CY1MieAJjSJSPVQvDFWs4AC+MWVs+6/mSnovT D1Mx30ve8awm8feJxGoGdn8wIXKMs84/EBbo20ICWpf5f7G1+pkAQpQUUYmmtQaE wkJ2j39amOmwS0SulRS5YIcHh3W/dWtHW1FasM= X-ME-Sender: X-Sasl-enc: vEg7z11CfaR8P7pMrPdTX8Hfbz4y2eCVCbCYhZdfE6J+ 1486283547 From: Daniel Shahaf To: zsh-workers@zsh.org Subject: [PATCH] vcs_info: Escape '%' signs in payloads Date: Sun, 5 Feb 2017 08:28:13 +0000 Message-Id: <1486283293-2586-1-git-send-email-danielsh@fujitsu.shahaf.local2> X-Mailer: git-send-email 2.1.4 In-Reply-To: <871svt8v4i.fsf@ft.bewatermyfriend.org> References: <871svt8v4i.fsf@ft.bewatermyfriend.org> Test case: a patch whose subject is '%Sfoo%sbar'. ('S' and 's' are expandos both in prompts and in the 'formats' style.) --- Doc/Zsh/contrib.yo | 17 +++++++++++++++++ Etc/BUGS | 7 ------- Functions/VCS_Info/Backends/VCS_INFO_get_data_hg | 1 + Functions/VCS_Info/VCS_INFO_set-patch-format | 14 ++++++++++++++ README | 9 +++++++++ 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index a454f60..5d0696d 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1344,6 +1344,12 @@ tt(branchformat), use tt(%%%%b). Sorry for this inconvenience, but it cannot be easily avoided. Luckily we do not clash with a lot of prompt expansions and this only needs to be done for those. +When one of the tt(gen-applied-string), tt(gen-unapplied-string), and +tt(set-patch-format) hooks is defined, +applying tt(%)-escaping (`tt(foo=${foo//'%'/%%})') to the interpolated values +for use in the prompt is the responsibility of those hooks (jointly); +when neither of those hooks is defined, tt(vcs_info) handles escaping by itself. +We regret this coupling, but it was required for backwards compatibility. subsect(Quilt Support) @@ -1616,6 +1622,9 @@ top-most patch and so forth. When setting tt(ret) to non-zero, the string in tt(${hook_com[applied-string]}) will be available as tt(%p) in the tt(patch-format) and tt(nopatch-format) styles. +This hook is, in concert with tt(set-patch-format), responsible for +tt(%)-escaping that value for use in the prompt. +(See the `Oddities' section.) ) item(tt(gen-unapplied-string))( Called in the tt(git) (with tt(stgit) or during rebase), and tt(hg) (with @@ -1629,6 +1638,9 @@ the patch next-in-line to be applied and so forth. When setting tt(ret) to non-zero, the string in tt(${hook_com[unapplied-string]}) will be available as tt(%u) in the tt(patch-format) and tt(nopatch-format) styles. +This hook is, in concert with tt(set-patch-format), responsible for +tt(%)-escaping that value for use in the prompt. +(See the `Oddities' section.) ) item(tt(gen-mqguards-string))( Called in the tt(hg) backend when tt(guards-string) is generated; the @@ -1706,6 +1718,11 @@ controllable in addition to that. If tt(ret) is set to non-zero, the string in tt(${hook_com[patch-replace]}) will be used unchanged instead of an expanded format from tt(patch-format) or tt(nopatch-format). + +This hook is, in concert with the tt(gen-applied-string) or +tt(gen-unapplied-string) hooks if they are defined, responsible for +tt(%)-escaping the final tt(patch-format) value for use in the prompt. +(See the `Oddities' section.) ) item(tt(set-message))( Called each time before a `tt(vcs_info_msg_)var(N)tt(_)' message is set. diff --git a/Etc/BUGS b/Etc/BUGS index a351464..008e337 100644 --- a/Etc/BUGS +++ b/Etc/BUGS @@ -15,13 +15,6 @@ It is currently impossible to time builtins. 40106: The comp* completion-related builtins (compadd, compset, etc) are run with $_comp_options in effect, rather than the user's options. ------------------------------------------------------------------------ -40240: vcs_info: percent escapes in payloads are interpreted - -Example: hg branch names and quilt patch subjects that contain the literal -string '%F{blue}', cause $vcs_info_msg_N_ to be rendered in blue. - -40240 has a patch, but 40241 explains why that patch is incomplete. ------------------------------------------------------------------------- users/20807: vcs_info quilt 'addon' mode: hook lookup context specifies the underlying VCS but not whether quilt is used. diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg index 143eb42..d403012 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg @@ -202,6 +202,7 @@ if zstyle -T ":vcs_info:${vcs}:${usercontext}:${rrn}" get-mq \ if VCS_INFO_hook 'gen-mqguards-string' "${mqguards[@]}"; then guards_string=${(j:,:)mqguards} + # TODO: %-escape extra_zformats[g:...] value else guards_string=${hook_com[guards-string]} fi diff --git a/Functions/VCS_Info/VCS_INFO_set-patch-format b/Functions/VCS_Info/VCS_INFO_set-patch-format index c5da368..cdf2d30 100644 --- a/Functions/VCS_Info/VCS_INFO_set-patch-format +++ b/Functions/VCS_Info/VCS_INFO_set-patch-format @@ -18,12 +18,15 @@ # - $hook_com is overwritten and the keys 'applied', 'applied-n', # 'unapplied', 'unapplied-n', 'all-n' are set. { + local applied_needs_escaping='unknown' + local unapplied_needs_escaping='unknown' if VCS_INFO_hook 'gen-applied-string' "${(@P)1}"; then if (( ${(P)#1} )); then REPLY=${(P)1[1]} else REPLY="" fi + applied_needs_escaping='yes' else REPLY=${hook_com[applied-string]} fi @@ -32,6 +35,7 @@ if VCS_INFO_hook 'gen-unapplied-string' "${(@P)3}"; then REPLY=${(P)#3} + unapplied_needs_escaping='yes' else REPLY=${hook_com[unapplied-string]} fi @@ -54,12 +58,22 @@ hook_com[all-n]=$(( ${hook_com[applied-n]} + ${hook_com[unapplied-n]} )) hook_com+=( ${7:+"${(@kvP)7}"} ) if VCS_INFO_hook 'set-patch-format' "${(P)6}"; then + # Escape the value for use in $PS1 + if [[ $applied_needs_escaping == 'yes' ]]; then + hook_com[applied]=${hook_com[applied]//'%'/%%} + fi + if [[ $unapplied_needs_escaping == 'yes' ]]; then + hook_com[unapplied]=${hook_com[unapplied]//'%'/%%} + fi + zformat -f REPLY "${(P)6}" "p:${hook_com[applied]}" "u:${hook_com[unapplied]}" \ "n:${hook_com[applied-n]}" "c:${hook_com[unapplied-n]}" \ "a:${hook_com[all-n]}" \ ${8:+"${(@P)8}"} else + unset applied_needs_escaping unapplied_needs_escaping # the hook deals with escaping REPLY=${hook_com[patch-replace]} fi hook_com=() + } diff --git a/README b/README index 26eb245..594b6f1 100644 --- a/README +++ b/README @@ -62,6 +62,15 @@ Note that functions including a non-leading / behave as before, e.g. if `dir/name' is found anywhere under a directory in $fpath it is loaded as a function named `dir/name'. +3) vcs_info: When neither a set-patch-format nor a gen-applied-string +(resp. gen-unapplied-string) hook is set, vcs_info now '%'-escapes the +applied-string (resp. unapplied-string) before interpolating it into the +patch-format string, to prevent literal `%' signs in the interpolated +value from being interpreted as prompt escape sequences. If you use +${vcs_info_msg_0_} in a context other than the shell prompt, you may need +to undo the escaping with: + print -v vcs_info_msg_0_ -Pr -- "${vcs_info_msg_0_}" + Incompatibilities between 5.0.8 and 5.3 ----------------------------------------