Patchwork [3,of,7] templater: check existence of closing brace of template string

login
register
mail settings
Submitter Yuya Nishihara
Date July 12, 2015, 2:54 p.m.
Message ID <04e18b2b2519bac75601.1436712898@mimosa>
Download mbox | patch
Permalink /patch/9955/
State Accepted
Headers show

Comments

Yuya Nishihara - July 12, 2015, 2:54 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1434377010 -32400
#      Mon Jun 15 23:03:30 2015 +0900
# Node ID 04e18b2b2519bac75601f659c0f5cea7ea610a4c
# Parent  6c48facea2ad500110e07700991dbad126156aca
templater: check existence of closing brace of template string

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -120,12 +120,12 @@  def tokenize(program, start, end):
             yield ('symbol', sym, s)
             pos -= 1
         elif c == '}':
-            pos += 1
-            break
+            yield ('end', None, pos + 1)
+            return
         else:
             raise error.ParseError(_("syntax error"), pos)
         pos += 1
-    yield ('end', None, pos)
+    raise error.ParseError(_("unterminated template expansion"), start)
 
 def _parsetemplate(tmpl, start, stop):
     parsed = []
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -2513,6 +2513,10 @@  Error on syntax:
   abort: t:3: unmatched quotes
   [255]
 
+  $ hg log -T '{date'
+  hg: parse error at 1: unterminated template expansion
+  [255]
+
 Behind the scenes, this will throw TypeError
 
   $ hg log -l 3 --template '{date|obfuscate}\n'