# HG changeset patch # User Yuya Nishihara # Date 1516106562 -32400 # Node ID 077ee15b8493f42b7a86b34d1d67c8097b5c4a65 # Parent 5a2d505a9174bab0072f2ebb953379b0b9576eda templater: make sure expression is terminated by '}' This can't be ensured by the tokenize() generator since the parser stop consuming tokens once it reached an end of an operation. Spotted by Matt Harbison. diff -r 5a2d505a9174 -r 077ee15b8493 mercurial/templater.py --- a/mercurial/templater.py Fri Jul 14 19:59:10 2017 +0200 +++ b/mercurial/templater.py Tue Jan 16 21:42:42 2018 +0900 @@ -184,6 +184,8 @@ return parsed, n + 1 parseres, pos = p.parse(tokenize(tmpl, n + 1, stop, '}')) + if not tmpl.endswith('}', n + 1, pos): + raise error.ParseError(_("invalid token"), pos) parsed.append(parseres) if quote: diff -r 5a2d505a9174 -r 077ee15b8493 tests/test-command-template.t --- a/tests/test-command-template.t Fri Jul 14 19:59:10 2017 +0200 +++ b/tests/test-command-template.t Tue Jan 16 21:42:42 2018 +0900 @@ -2756,6 +2756,15 @@ $ hg log -T '{date' hg: parse error at 1: unterminated template expansion [255] + $ hg log -T '{date(}' + hg: parse error at 7: not a prefix: end + [255] + $ hg log -T '{date)}' + hg: parse error at 5: invalid token + [255] + $ hg log -T '{date date}' + hg: parse error at 6: invalid token + [255] Behind the scenes, this will throw TypeError