Submitter | Yuya Nishihara |
---|---|
Date | Aug. 28, 2015, 2:54 p.m. |
Message ID | <534ed63b7cf44765e68e.1440773675@mimosa> |
Download | mbox | patch |
Permalink | /patch/10314/ |
State | Changes Requested |
Headers | show |
Comments
On Fri, 2015-08-28 at 23:54 +0900, Yuya Nishihara wrote: > +common mistake of template syntax, trailing slash (issue4798) > + > + $ hg id trslash:// > + hg: parse error at 0: syntax error > + [255] I don't think this is an improvement. Before this would complain about a trailing backslash (but not say why that was a problem: because it's not a valid template), now this has an even less helpful "syntax error" and points to position 0 (where nothing is amiss). It does avoid spewing a backtrace though! I think changing "syntax error" to "string escaping error in template" might be better. Might be more clear to test against: $ hg log -T "\\" Also: you write slash instead of backslash a few places.
Patch
diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -147,7 +147,11 @@ def _parsetemplate(tmpl, start, stop, qu n = min((tmpl.find(c, pos, stop) for c in sepchars), key=lambda n: (n < 0, n)) if n < 0: - parsed.append(('string', tmpl[pos:stop].decode('string-escape'))) + try: + parsed.append(('string', + tmpl[pos:stop].decode('string-escape'))) + except ValueError: # unbalanced escapes + raise error.ParseError(_("syntax error"), pos) pos = stop break c = tmpl[n] diff --git a/tests/test-schemes.t b/tests/test-schemes.t --- a/tests/test-schemes.t +++ b/tests/test-schemes.t @@ -9,6 +9,8 @@ > parts = http://{1}:$HGPORT/ > z = file:\$PWD/ > EOF + $ printf 'trslash = c:\\' >> $HGRCPATH + $ hg init test $ cd test $ echo a > a @@ -52,6 +54,12 @@ check that paths are expanded no changes found [1] +common mistake of template syntax, trailing slash (issue4798) + + $ hg id trslash:// + hg: parse error at 0: syntax error + [255] + errors $ cat errors.log