Patchwork [1,of,7] revsetlang: catch invalid format character with %l prefix

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

Comments

Yuya Nishihara - Jan. 8, 2018, 1:36 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1491034711 -32400
#      Sat Apr 01 17:18:31 2017 +0900
# Node ID ff1321fe23fd7f401bb9dbfc29d99bc639ed3a24
# Parent  4c3a4bb31c0e3d9b8920b4c9b64ae930b1fe52ce
revsetlang: catch invalid format character with %l prefix

listexp() could call argtype() with an invalid format character, but that
wasn't checked before.

Patch

diff --git a/mercurial/revsetlang.py b/mercurial/revsetlang.py
--- a/mercurial/revsetlang.py
+++ b/mercurial/revsetlang.py
@@ -600,6 +600,7 @@  def formatspec(expr, *args):
             return _quote(node.hex(arg))
         elif c == 'b':
             return _quote(arg.branch())
+        raise error.ParseError(_('unexpected revspec format character %s') % c)
 
     def listexp(s, t):
         l = len(s)
@@ -633,16 +634,13 @@  def formatspec(expr, *args):
         d = expr[pos]
         if d == '%':
             ret.append(d)
-        elif d in 'dsnbr':
-            ret.append(argtype(d, next(argiter)))
         elif d == 'l':
             # a list of some type
             pos += 1
             d = expr[pos]
             ret.append(listexp(list(next(argiter)), d))
         else:
-            raise error.ParseError(_('unexpected revspec format character %s')
-                                   % d)
+            ret.append(argtype(d, next(argiter)))
         pos += 1
 
     return ''.join(ret)
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
@@ -4085,6 +4085,9 @@  Invalid arguments passed to revset()
   $ hg log -T '{revset("%whatever", 0)}\n'
   hg: parse error: unexpected revspec format character w
   [255]
+  $ hg log -T '{revset("%lwhatever", files)}\n'
+  hg: parse error: unexpected revspec format character w
+  [255]
 
 Test files function