[PATCH] parser: avoid IndexError: tuple index out of range

timeless timeless at gmail.com
Fri Jun 18 07:14:51 CDT 2010


I was playing around with revsets and hit:

hg log -r 'ancestor(1::5) !'

IndexError: tuple index out of range

It seems less than ideal. I don't see any obvious tests for the
parser, so I'm just proposing the obvious patch.

# HG changeset patch
# User timeless <timeless at gmail.com>
# Date 1276863115 -10800
# Node ID a5d65e8bf55bd314d0dbef9a6bba64936e08f7ee
# Parent  4125f72e5108b1a7e1ebe362ffebdbfbd47b11cd
parser: avoid IndexError: tuple index out of range

diff --git a/mercurial/parser.py b/mercurial/parser.py
--- a/mercurial/parser.py
+++ b/mercurial/parser.py
@@ -62,6 +62,8 @@ class parser(object):
                 expr = (suffix[0], expr)
             else:
                 # handle infix rules
+                if len (self._elements[token]) < 3:
+                    raise error.ParseError("not an infix: %s" % token, pos)
                 infix = self._elements[token][2]
                 if len(infix) == 3 and infix[2] == self.current[0]:
                     self._match(infix[2], pos)


More information about the Mercurial-devel mailing list