[PATCH 3 of 7] revsetlang: check incomplete revspec format character

Yuya Nishihara yuya at tcha.org
Mon Jan 8 08:36:26 EST 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1491035308 -32400
#      Sat Apr 01 17:28:28 2017 +0900
# Node ID 32eb47c4665d7353ed4f1f403a6f061344213152
# Parent  b8a9d4009b3476895b02b38aca22e3dd2e4fc1b8
revsetlang: check incomplete revspec format character

diff --git a/mercurial/revsetlang.py b/mercurial/revsetlang.py
--- a/mercurial/revsetlang.py
+++ b/mercurial/revsetlang.py
@@ -631,7 +631,10 @@ def formatspec(expr, *args):
             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 @@ def formatspec(expr, *args):
         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))
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
@@ -4097,6 +4097,12 @@ Invalid arguments passed to revset()
   $ 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
 


More information about the Mercurial-devel mailing list