Patchwork [1,of,7] templater: respect stop position while parsing template string

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

Comments

Yuya Nishihara - July 12, 2015, 2:54 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1434376842 -32400
#      Mon Jun 15 23:00:42 2015 +0900
# Node ID 0bdccc00e5aaba80b379ad6eda4917958f9f30e3
# Parent  026105c442d7f20d239c1e5e5fac1cfa080323da
templater: respect stop position while parsing template string

It has no effect now because stop is len(tmpl).

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -132,9 +132,10 @@  def compiletemplate(tmpl, context):
     pos, stop = 0, len(tmpl)
     p = parser.parser(elements)
     while pos < stop:
-        n = tmpl.find('{', pos)
+        n = tmpl.find('{', pos, stop)
         if n < 0:
-            parsed.append(('string', tmpl[pos:]))
+            parsed.append(('string', tmpl[pos:stop]))
+            pos = stop
             break
         bs = (n - pos) - len(tmpl[pos:n].rstrip('\\'))
         if bs % 2 == 1: