# HG changeset patch # User Matt Harbison # Date 2015-10-05 16:37:26 # Node ID 4ca98a3891526b825ec490e9055aa1c4a91db9ae # Parent 93bfa9fc96e31f1cc5f444bdc2436966c665cf1f templater: protect word() from crashing on out of range negative value The function isn't documented to work with negative values at all, but it does, which can be useful. However, the range check didn't account for this. diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -649,7 +649,7 @@ def word(context, mapping, args): splitter = None tokens = text.split(splitter) - if num >= len(tokens): + if num >= len(tokens) or num < -len(tokens): return '' else: return tokens[num] 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 @@ -3368,6 +3368,11 @@ Test word for invalid numbers hg: parse error: word expects an integer index [255] +Test word for out of range + + $ hg log -R a --template "{word(10000, desc)}" + $ hg log -R a --template "{word(-10000, desc)}" + Test indent and not adding to empty lines $ hg log -T "-----\n{indent(desc, '>> ', ' > ')}\n" -r 0:1 -R a