Mercurial > hg
changeset 35680:077ee15b8493
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.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Tue, 16 Jan 2018 21:42:42 +0900 |
parents | 5a2d505a9174 |
children | e29823c6d3e8 |
files | mercurial/templater.py tests/test-command-template.t |
diffstat | 2 files changed, 11 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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:
--- 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