[PATCH 3 of 6 V3] templatefilters: don't stringify None into "None"

Yuya Nishihara yuya at tcha.org
Sun May 10 17:36:37 CDT 2015


On Sun, 10 May 2015 14:44:43 -0400, Jordi GutiƩrrez Hermoso wrote:
> # HG changeset patch
> # User Jordi GutiƩrrez Hermoso <jordigh at octave.org>
> # Date 1431279231 14400
> #      Sun May 10 13:33:51 2015 -0400
> # Node ID 341419c705647953b0b5958a652a6918f15fbb23
> # Parent  f55866c0fb93041bd435a2af78de4f1043dea774
> templatefilters: don't stringify None into "None"
> 
> A few template keywords can in fact return None, such as {bisect}. In
> some contexts, these get stringified into None instead of "". This is
> leaking Python details into the UI.
> 
> diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
> --- a/mercurial/templatefilters.py
> +++ b/mercurial/templatefilters.py
> @@ -326,6 +326,8 @@ def stringify(thing):
>      """
>      if util.safehasattr(thing, '__iter__') and not isinstance(thing, str):
>          return "".join([stringify(t) for t in thing if t is not None])
> +    if thing is None:
> +        return ""
>      return str(thing)

+1. This is what templater._flatten() does implicitly. stringify should do
the same way.

http://selenic.com/repo/hg/file/015adbcd92f3/mercurial/templater.py#l603


More information about the Mercurial-devel mailing list