[PATCH] templater: fix list templating bug

Sean Farley sean at farley.io
Wed Feb 24 15:06:07 EST 2016


Kostia Balytskyi <ikostia at fb.com> writes:

> # HG changeset patch
> # User Kostia Balytskyi <ikostia at fb.com>
> # Date 1456342315 0
> #      Wed Feb 24 19:31:55 2016 +0000
> # Node ID 35b419186b8060d97e0fb3f2fccccbe5815a534c
> # Parent  1d3998abd58ad32bd17381e14a530ff7ff175d48
> templater: fix list templating bug
>
> High-level use case: printing a list of object with formatter
> when each object in turn contains a list of properties (like
> when % template symbold is used in {things % '{thing}'}
>
> Let the top-level list contain one thing with two properties:
> objs = [{
>    'props': [
>      { 'value': 1, 'show': 1 },
>      { 'value': 2 }]
> }]
> (please note that second property does not have 'show' key)
>
> If a templateformatter is used to print this with template
>   "{props % '{if(show, value)}'}"
> current implementation will print value for both properties,
> which is a bug. This happens because in `templater.runmap`
> function we only rewrite mapping values with existing new
> values for each item. If some mapping value is missing in
> the item, it will not be removed.

Nice catch. Looks good to me.


More information about the Mercurial-devel mailing list