Patchwork [2,of,7] revsetlang: check number of arguments passed to formatspec()

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 8, 2018, 1:36 p.m.
Message ID <b8a9d4009b3476895b02.1515418585@mimosa>
Download mbox | patch
Permalink /patch/26611/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 8, 2018, 1:36 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1491035145 -32400
#      Sat Apr 01 17:25:45 2017 +0900
# Node ID b8a9d4009b3476895b02b38aca22e3dd2e4fc1b8
# Parent  ff1321fe23fd7f401bb9dbfc29d99bc639ed3a24
revsetlang: check number of arguments passed to formatspec()

Patch

diff --git a/mercurial/revsetlang.py b/mercurial/revsetlang.py
--- a/mercurial/revsetlang.py
+++ b/mercurial/revsetlang.py
@@ -634,15 +634,27 @@  def formatspec(expr, *args):
         d = expr[pos]
         if d == '%':
             ret.append(d)
-        elif d == 'l':
+            pos += 1
+            continue
+
+        try:
+            arg = next(argiter)
+        except StopIteration:
+            raise error.ParseError(_('missing argument for revspec'))
+        if d == 'l':
             # a list of some type
             pos += 1
             d = expr[pos]
-            ret.append(listexp(list(next(argiter)), d))
+            ret.append(listexp(list(arg), d))
         else:
-            ret.append(argtype(d, next(argiter)))
+            ret.append(argtype(d, arg))
         pos += 1
 
+    try:
+        next(argiter)
+        raise error.ParseError(_('too many revspec arguments specified'))
+    except StopIteration:
+        pass
     return ''.join(ret)
 
 def prettyformat(tree):
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
@@ -4088,6 +4088,15 @@  Invalid arguments passed to revset()
   $ hg log -T '{revset("%lwhatever", files)}\n'
   hg: parse error: unexpected revspec format character w
   [255]
+  $ hg log -T '{revset("%s %s", 0)}\n'
+  hg: parse error: missing argument for revspec
+  [255]
+  $ hg log -T '{revset("", 0)}\n'
+  hg: parse error: too many revspec arguments specified
+  [255]
+  $ hg log -T '{revset("%s", 0, 1)}\n'
+  hg: parse error: too many revspec arguments specified
+  [255]
 
 Test files function