Mercurial > public > mercurial-scm > hg-stable
diff mercurial/templater.py @ 36716:1b179d151578
templater: fix position of terminator character in error message
Since a template expression starts after the '{' character, the expression
should be considered to end immediately before the terminator '{'.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 04 Mar 2018 07:03:50 -0500 |
parents | 44048f1bcee5 |
children | e79adc12cde3 |
line wrap: on
line diff
--- a/mercurial/templater.py Sun Mar 04 10:42:51 2018 -0500 +++ b/mercurial/templater.py Sun Mar 04 07:03:50 2018 -0500 @@ -145,7 +145,7 @@ yield ('symbol', sym, s) pos -= 1 elif c == term: - yield ('end', None, pos + 1) + yield ('end', None, pos) return else: raise error.ParseError(_("syntax error"), pos) @@ -237,9 +237,10 @@ return parseres, pos = p.parse(tokenize(tmpl, n + 1, stop, '}')) - if not tmpl.endswith('}', n + 1, pos): + if not tmpl.startswith('}', pos): raise error.ParseError(_("invalid token"), pos) yield ('template', parseres, n) + pos += 1 if quote: raise error.ParseError(_("unterminated string"), start) @@ -253,9 +254,10 @@ tmpl = tmpl.replace('\n', br'\n') # We want the caret to point to the place in the template that # failed to parse, but in a hint we get a open paren at the - # start. Therefore, we print "loc" spaces (instead of "loc - 1") + # start. Therefore, we print "loc + 1" spaces (instead of "loc") # to line up the caret with the location of the error. - inst.hint = tmpl + '\n' + ' ' * (loc + offset) + '^ ' + _('here') + inst.hint = (tmpl + '\n' + + ' ' * (loc + 1 + offset) + '^ ' + _('here')) raise yield ('end', None, pos)