Skip to content
Snippets Groups Projects
Commit 09124cce authored by Yuya Nishihara's avatar Yuya Nishihara
Browse files

templater: fix crash by passing invalid object to date() function

"date information" is somewhat obscure, but we call it that way in
templatekw.showdate().
parent 986a5c23
No related branches found
No related tags found
No related merge requests found
......@@ -226,5 +226,6 @@
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]))
......@@ -229,7 +230,13 @@
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
......
......@@ -2236,6 +2236,12 @@
date: 70 01 01 01 +0000
date: 70 01 01 00 +0000
Test invalid date:
$ hg log -R latesttag -T '{date(rev)}\n'
hg: parse error: date expects a date information
[255]
Test string escaping:
$ hg log -R latesttag -r 0 --template '>\n<>\\n<{if(rev, "[>\n<>\\n<]")}>\n<>\\n<\n'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment