diff options
author | Daniel Shahaf <d.s@daniel.shahaf.name> | 2017-02-05 08:28:13 +0000 |
---|---|---|
committer | Daniel Shahaf <d.s@daniel.shahaf.name> | 2017-02-09 15:24:04 +0000 |
commit | ecd88284f358cbcd787757184bbf8704779cab1a (patch) | |
tree | 98fc9e76a873dc91e18a8295070373d9727ac551 | |
parent | e3bc63f00e1a11df6a8a214a5d4a2e3feb59f28a (diff) | |
download | zsh-ecd88284f358cbcd787757184bbf8704779cab1a.tar.gz zsh-ecd88284f358cbcd787757184bbf8704779cab1a.tar.xz zsh-ecd88284f358cbcd787757184bbf8704779cab1a.zip |
40492: vcs_info: Escape '%' signs in payloads.
Test case: a patch whose subject is '%Sfoo%sbar'. ('S' and 's' are expandos both in prompts and in the 'formats' style.)
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | Doc/Zsh/contrib.yo | 17 | ||||
-rw-r--r-- | Etc/BUGS | 7 | ||||
-rw-r--r-- | Functions/VCS_Info/Backends/VCS_INFO_get_data_hg | 1 | ||||
-rw-r--r-- | Functions/VCS_Info/VCS_INFO_set-patch-format | 14 | ||||
-rw-r--r-- | README | 9 |
6 files changed, 48 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog index 051a76b8c..787c27e1e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2017-02-09 Daniel Shahaf <d.s@daniel.shahaf.name> + + * 40492: Doc/Zsh/contrib.yo, Etc/BUGS, + Functions/VCS_Info/Backends/VCS_INFO_get_data_hg, + Functions/VCS_Info/VCS_INFO_set-patch-format, README: vcs_info: + Escape '%' signs in payloads. + 2017-02-08 Daniel Shahaf <d.s@daniel.shahaf.name> * unposted: Completion/Unix/Command/_subversion: _svn: Fix diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index a454f60a3..5d0696dcc 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 a351464ac..008e337ca 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 143eb42f0..d4030125c 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 c5da36808..cdf2d303e 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 26eb24550..594b6f1cd 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 ---------------------------------------- |