Mercurial > hg-stable
changeset 30116:1c01fa29630f
templater: handle division by zero in arithmetic
For now, just turn it to an abort.
author | Simon Farnsworth <simonfar@fb.com> |
---|---|
date | Sun, 09 Oct 2016 08:09:20 -0700 |
parents | 8e42dfde93d1 |
children | b85fa6bf298b |
files | mercurial/templater.py |
diffstat | 1 files changed, 6 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/templater.py Sun Oct 09 05:51:04 2016 -0700 +++ b/mercurial/templater.py Sun Oct 09 08:09:20 2016 -0700 @@ -439,7 +439,10 @@ _('arithmetic only defined on integers')) right = evalinteger(context, mapping, right, _('arithmetic only defined on integers')) - return func(left, right) + try: + return func(left, right) + except ZeroDivisionError: + raise error.Abort(_('division by zero is not defined')) def buildfunc(exp, context): n = getsymbol(exp[1]) @@ -741,12 +744,8 @@ # i18n: "mod" is a keyword raise error.ParseError(_("mod expects two arguments")) - left = evalinteger(context, mapping, args[0], - _('arithmetic only defined on integers')) - right = evalinteger(context, mapping, args[1], - _('arithmetic only defined on integers')) - - return left % right + func = lambda a, b: a % b + return runarithmetic(context, mapping, (func, args[0], args[1])) @templatefunc('relpath(path)') def relpath(context, mapping, args):