revsetlang: catch invalid format character with %l prefix
authorYuya Nishihara <yuya@tcha.org>
Sat, 01 Apr 2017 17:18:31 +0900
changeset 35591 8f1a7adb3225
parent 35590 aaeba70d5cbe
child 35592 0fd617afebc0
revsetlang: catch invalid format character with %l prefix listexp() could call argtype() with an invalid format character, but that wasn't checked before.
mercurial/revsetlang.py
tests/test-command-template.t
--- a/mercurial/revsetlang.py	Fri Dec 29 06:32:17 2017 +0530
+++ b/mercurial/revsetlang.py	Sat Apr 01 17:18:31 2017 +0900
@@ -600,6 +600,7 @@
             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 @@
         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)
--- a/tests/test-command-template.t	Fri Dec 29 06:32:17 2017 +0530
+++ b/tests/test-command-template.t	Sat Apr 01 17:18:31 2017 +0900
@@ -4085,6 +4085,9 @@
   $ 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