Patchwork templater: fix crash by empty group expression

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 18, 2018, 12:07 p.m.
Message ID <927c55b5ae4ebb16b01d.1516277278@mimosa>
Download mbox | patch
Permalink /patch/26860/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 18, 2018, 12:07 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1516114201 -32400
#      Tue Jan 16 23:50:01 2018 +0900
# Node ID 927c55b5ae4ebb16b01da9a2ac60539ecc6bb234
# Parent  604c08ad12c4c3a2fdf182cdf90d5d4acaa25c9e
templater: fix crash by empty group expression

'exp' may be None because of '(group None)' node. The error message is copied
from revset.py.
Augie Fackler - Jan. 19, 2018, 7:50 p.m.
On Thu, Jan 18, 2018 at 09:07:58PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1516114201 -32400
> #      Tue Jan 16 23:50:01 2018 +0900
> # Node ID 927c55b5ae4ebb16b01da9a2ac60539ecc6bb234
> # Parent  604c08ad12c4c3a2fdf182cdf90d5d4acaa25c9e
> templater: fix crash by empty group expression

queued, thanks

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -259,6 +259,8 @@  def prettyformat(tree):
 
 def compileexp(exp, context, curmethods):
     """Compile parsed template tree to (func, data) pair"""
+    if not exp:
+        raise error.ParseError(_("missing argument"))
     t = exp[0]
     if t in curmethods:
         return curmethods[t](exp, context)
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -2766,6 +2766,16 @@  Error on syntax:
   hg: parse error at 6: invalid token
   [255]
 
+  $ hg log -T '{}'
+  hg: parse error at 2: not a prefix: end
+  [255]
+  $ hg debugtemplate -v '{()}'
+  (template
+    (group
+      None))
+  hg: parse error: missing argument
+  [255]
+
 Behind the scenes, this will throw TypeError
 
   $ hg log -l 3 --template '{date|obfuscate}\n'