Patchwork templatefuncs: do not crash because of invalid value fed to mailmap()

login
register
mail settings
Submitter Yuya Nishihara
Date April 1, 2018, 2:45 a.m.
Message ID <02079695afdd39020b13.1522550741@mimosa>
Download mbox | patch
Permalink /patch/30087/
State Accepted
Headers show

Comments

Yuya Nishihara - April 1, 2018, 2:45 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1522548389 -32400
#      Sun Apr 01 11:06:29 2018 +0900
# Node ID 02079695afdd39020b13f238c69691dce14b932f
# Parent  2ed180117f7658d0cbf6a1ece20944465c55c947
templatefuncs: do not crash because of invalid value fed to mailmap()
Gregory Szorc - April 1, 2018, 6:41 p.m.
On Sat, Mar 31, 2018 at 7:45 PM, Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1522548389 -32400
> #      Sun Apr 01 11:06:29 2018 +0900
> # Node ID 02079695afdd39020b13f238c69691dce14b932f
> # Parent  2ed180117f7658d0cbf6a1ece20944465c55c947
> templatefuncs: do not crash because of invalid value fed to mailmap()
>

Queued.


>
> diff --git a/mercurial/templatefuncs.py b/mercurial/templatefuncs.py
> --- a/mercurial/templatefuncs.py
> +++ b/mercurial/templatefuncs.py
> @@ -175,7 +175,7 @@ def mailmap(context, mapping, args):
>      if len(args) != 1:
>          raise error.ParseError(_("mailmap expects one argument"))
>
> -    author = evalfuncarg(context, mapping, args[0])
> +    author = evalstring(context, mapping, args[0])
>
>      cache = context.resource(mapping, 'cache')
>      repo = context.resource(mapping, 'repo')
> diff --git a/tests/test-mailmap.t b/tests/test-mailmap.t
> --- a/tests/test-mailmap.t
> +++ b/tests/test-mailmap.t
> @@ -65,3 +65,8 @@ A commit with improperly formatted user
>    Proper Name 4 <proper@m.c>
>    Testuser <newmmentry@m.c>
>    Improper user
> +
> +No TypeError beacause of invalid input
> +
> +  $ hg log -T '{mailmap(termwidth)}\n' -r0
> +  80
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/mercurial/templatefuncs.py b/mercurial/templatefuncs.py
--- a/mercurial/templatefuncs.py
+++ b/mercurial/templatefuncs.py
@@ -175,7 +175,7 @@  def mailmap(context, mapping, args):
     if len(args) != 1:
         raise error.ParseError(_("mailmap expects one argument"))
 
-    author = evalfuncarg(context, mapping, args[0])
+    author = evalstring(context, mapping, args[0])
 
     cache = context.resource(mapping, 'cache')
     repo = context.resource(mapping, 'repo')
diff --git a/tests/test-mailmap.t b/tests/test-mailmap.t
--- a/tests/test-mailmap.t
+++ b/tests/test-mailmap.t
@@ -65,3 +65,8 @@  A commit with improperly formatted user 
   Proper Name 4 <proper@m.c>
   Testuser <newmmentry@m.c>
   Improper user
+
+No TypeError beacause of invalid input
+
+  $ hg log -T '{mailmap(termwidth)}\n' -r0
+  80