Mercurial > hg
comparison mercurial/templater.py @ 24949:890845af1ac2 stable
templater: strictly parse leading backslashes of '{' (issue4569) (BC)
Because double backslashes are processed as a string escape sequence, '\\{'
should start the template syntax. On the other hand, r'' disables any sort
of \-escapes, so r'\{' can go either way, never start the template syntax
or always start it. I simply chose the latter, which means r'\{' is the same
as '\\{'.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 04 May 2015 10:17:34 +0900 |
parents | db7463aa080f |
children | 554d6fcc3c84 7298da81f5a9 |
comparison
equal
deleted
inserted
replaced
24948:db7463aa080f | 24949:890845af1ac2 |
---|---|
85 while pos < stop: | 85 while pos < stop: |
86 n = tmpl.find('{', pos) | 86 n = tmpl.find('{', pos) |
87 if n < 0: | 87 if n < 0: |
88 parsed.append((strtoken, tmpl[pos:])) | 88 parsed.append((strtoken, tmpl[pos:])) |
89 break | 89 break |
90 if n > 0 and tmpl[n - 1] == '\\': | 90 bs = (n - pos) - len(tmpl[pos:n].rstrip('\\')) |
91 # escaped | 91 if strtoken == 'string' and bs % 2 == 1: |
92 # escaped (e.g. '\{', '\\\{', but not '\\{' nor r'\{') | |
92 parsed.append((strtoken, (tmpl[pos:n - 1] + "{"))) | 93 parsed.append((strtoken, (tmpl[pos:n - 1] + "{"))) |
93 pos = n + 1 | 94 pos = n + 1 |
94 continue | 95 continue |
95 if n > pos: | 96 if n > pos: |
96 parsed.append((strtoken, tmpl[pos:n])) | 97 parsed.append((strtoken, tmpl[pos:n])) |