Mercurial > public > mercurial-scm > hg-stable
diff mercurial/templater.py @ 24903:09124cce913f stable
templater: fix crash by passing invalid object to date() function
"date information" is somewhat obscure, but we call it that way in
templatekw.showdate().
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 03 May 2015 17:33:14 +0900 |
parents | 10a13da8840d |
children | db7463aa080f |
line wrap: on
line diff
--- a/mercurial/templater.py Sun May 03 12:49:15 2015 -0700 +++ b/mercurial/templater.py Sun May 03 17:33:14 2015 +0900 @@ -226,10 +226,17 @@ raise error.ParseError(_("date expects one or two arguments")) date = args[0][0](context, mapping, args[0][1]) + fmt = None if len(args) == 2: fmt = stringify(args[1][0](context, mapping, args[1][1])) - return util.datestr(date, fmt) - return util.datestr(date) + try: + if fmt is None: + return util.datestr(date) + else: + return util.datestr(date, fmt) + except (TypeError, ValueError): + # i18n: "date" is a keyword + raise error.ParseError(_("date expects a date information")) def diff(context, mapping, args): """:diff([includepattern [, excludepattern]]): Show a diff, optionally