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

Re: vcs_info: '%' in payloads not escaped

Frank Terbeck wrote on Thu, Jan 05, 2017 at 17:27:06 +0100:
> Hey Daniel!
> Daniel Shahaf wrote:
> [...]
> > How about the following?
> >          else
> >              git_applied_s=""
> >          fi
> > +        git_applied_s=${git_applied_s//'%'/%%}
> >      else
> [...]
> >          git_patches_unapplied=${#git_patches_unapplied}
> > +        git_patches_unapplied=${git_patches_unapplied//'%'/%%}
> >      else
> I honestly don't know. Isn't this like kind-of-predictable behavior
> versus a — potentially — a lot of special cases? I don't think that it's
> possible to get this right in the general case. It's in-band data that
> is indistinguishable from data that is interpreted by something that
> interprets zsh's prompt language.

A lot of special cases, how?  $git_applied_s contains a string derived
from git, so we know that any and all percent signs in it need escaping.
That's why the escaping is done before the first zformat call, and only
if user hooks were not called: because that's the only case in which we
know for certain what does and doesn't need escaping.

With this patch, the following invariant holds: immediately after the
`fi` that ends the `if VCS_INFO_hook …` condition, $git_applied_s is
properly %-escaped — either via the hook obeying the `Oddities'
contract, or (if there's no hook) via the code added by this patch.

I'm sure there's a way to escape payloads sanely, and we just need to
figure out what that is...



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