changeset 35593:850cd045b1df

revsetlang: check incomplete revspec format character
author Yuya Nishihara <yuya@tcha.org>
date Sat, 01 Apr 2017 17:28:28 +0900
parents 0fd617afebc0
children 468d7a1f6633
files mercurial/revsetlang.py tests/test-command-template.t
diffstat 2 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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