diff mercurial/parser.py @ 42232:29798c9ba5c9 stable

parser: fix crash by parsing "()" in keyword argument position A tree node can be either None or a tuple because x=("group", None) is reduced to x[1].
author Yuya Nishihara <yuya@tcha.org>
date Fri, 03 May 2019 20:06:03 +0900
parents 0a2ce5b43574
children 2372284d9457
line wrap: on
line diff
--- a/mercurial/parser.py	Wed May 01 14:27:19 2019 -0400
+++ b/mercurial/parser.py	Fri May 03 20:06:03 2019 +0900
@@ -147,7 +147,8 @@
     arguments are rejected, but missing keyword arguments are just omitted.
     """
     poskeys, varkey, keys, optkey = argspec
-    kwstart = next((i for i, x in enumerate(trees) if x[0] == keyvaluenode),
+    kwstart = next((i for i, x in enumerate(trees)
+                    if x and x[0] == keyvaluenode),
                    len(trees))
     if kwstart < len(poskeys):
         raise error.ParseError(_("%(func)s takes at least %(nargs)d positional "
@@ -171,7 +172,7 @@
     if optkey:
         args[optkey] = util.sortdict()
     for x in trees[kwstart:]:
-        if x[0] != keyvaluenode or x[1][0] != keynode:
+        if not x or x[0] != keyvaluenode or x[1][0] != keynode:
             raise error.ParseError(_("%(func)s got an invalid argument")
                                    % {'func': funcname})
         k = x[1][1]