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].
--- 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]
--- a/tests/test-revset.t Wed May 01 14:27:19 2019 -0400
+++ b/tests/test-revset.t Fri May 03 20:06:03 2019 +0900
@@ -472,6 +472,12 @@
$ log 'extra(unknown=branch)'
hg: parse error: extra got an unexpected keyword argument 'unknown'
[255]
+ $ log 'extra((), x)'
+ hg: parse error: first argument to extra must be a string
+ [255]
+ $ log 'extra(label=x, ())'
+ hg: parse error: extra got an invalid argument
+ [255]
$ try 'foo=bar|baz'
(keyvalue