revsetlang: check incomplete revspec format character
authorYuya Nishihara <yuya@tcha.org>
Sat, 01 Apr 2017 17:28:28 +0900
changeset 35593 850cd045b1df
parent 35592 0fd617afebc0
child 35594 468d7a1f6633
revsetlang: check incomplete revspec format character
mercurial/revsetlang.py
tests/test-command-template.t
--- a/mercurial/revsetlang.py	Sat Apr 01 17:25:45 2017 +0900
+++ b/mercurial/revsetlang.py	Sat Apr 01 17:28:28 2017 +0900
@@ -631,7 +631,10 @@
             break
         ret.append(expr[pos:q])
         pos = q + 1
-        d = expr[pos]
+        try:
+            d = expr[pos]
+        except IndexError:
+            raise error.ParseError(_('incomplete revspec format character'))
         if d == '%':
             ret.append(d)
             pos += 1
@@ -644,7 +647,10 @@
         if d == 'l':
             # a list of some type
             pos += 1
-            d = expr[pos]
+            try:
+                d = expr[pos]
+            except IndexError:
+                raise error.ParseError(_('incomplete revspec format character'))
             ret.append(listexp(list(arg), d))
         else:
             ret.append(argtype(d, arg))
--- a/tests/test-command-template.t	Sat Apr 01 17:25:45 2017 +0900
+++ b/tests/test-command-template.t	Sat Apr 01 17:28:28 2017 +0900
@@ -4097,6 +4097,12 @@
   $ hg log -T '{revset("%s", 0, 1)}\n'
   hg: parse error: too many revspec arguments specified
   [255]
+  $ hg log -T '{revset("%", 0)}\n'
+  hg: parse error: incomplete revspec format character
+  [255]
+  $ hg log -T '{revset("%l", 0)}\n'
+  hg: parse error: incomplete revspec format character
+  [255]
 
 Test files function