##// END OF EJS Templates
templater: fix escaping in nested string literals (issue4102)...
Matt Mackall -
r20066:64b4f0cd stable
parent child Browse files
Show More
@@ -940,9 +940,7 b' def show_changeset(ui, repo, opts, buffe'
940
940
941 tmpl = opts.get('template')
941 tmpl = opts.get('template')
942 style = None
942 style = None
943 if tmpl:
943 if not tmpl:
944 tmpl = templater.parsestring(tmpl, quoted=False)
945 else:
946 style = opts.get('style')
944 style = opts.get('style')
947
945
948 # ui settings
946 # ui settings
@@ -52,7 +52,7 b' def tokenizer(data):'
52 if not decode:
52 if not decode:
53 yield ('string', program[s:pos].replace('\\', r'\\'), s)
53 yield ('string', program[s:pos].replace('\\', r'\\'), s)
54 break
54 break
55 yield ('string', program[s:pos].decode('string-escape'), s)
55 yield ('string', program[s:pos], s)
56 break
56 break
57 pos += 1
57 pos += 1
58 else:
58 else:
@@ -80,19 +80,19 b' def compiletemplate(tmpl, context):'
80 parsed = []
80 parsed = []
81 pos, stop = 0, len(tmpl)
81 pos, stop = 0, len(tmpl)
82 p = parser.parser(tokenizer, elements)
82 p = parser.parser(tokenizer, elements)
83
84 while pos < stop:
83 while pos < stop:
85 n = tmpl.find('{', pos)
84 n = tmpl.find('{', pos)
86 if n < 0:
85 if n < 0:
87 parsed.append(("string", tmpl[pos:]))
86 parsed.append(("string", tmpl[pos:].decode("string-escape")))
88 break
87 break
89 if n > 0 and tmpl[n - 1] == '\\':
88 if n > 0 and tmpl[n - 1] == '\\':
90 # escaped
89 # escaped
91 parsed.append(("string", tmpl[pos:n - 1] + "{"))
90 parsed.append(("string",
91 (tmpl[pos:n - 1] + "{").decode("string-escape")))
92 pos = n + 1
92 pos = n + 1
93 continue
93 continue
94 if n > pos:
94 if n > pos:
95 parsed.append(("string", tmpl[pos:n]))
95 parsed.append(("string", tmpl[pos:n].decode("string-escape")))
96
96
97 pd = [tmpl, n + 1, stop]
97 pd = [tmpl, n + 1, stop]
98 parseres, pos = p.parse(pd)
98 parseres, pos = p.parse(pd)
@@ -80,8 +80,8 b''
80 return m ? m[1] : null;
80 return m ? m[1] : null;
81 },
81 },
82 '.bigtable > tbody:nth-of-type(2)',
82 '.bigtable > tbody:nth-of-type(2)',
83 '<tr class="%class%">\
83 '<tr class="%class%">\\
84 <td colspan="3" style="text-align: center;">%text%</td>\
84 <td colspan="3" style="text-align: center;">%text%</td>\\
85 </tr>'
85 </tr>'
86 );
86 );
87 </script>
87 </script>
@@ -1586,3 +1586,11 b' Test the strip function with chars speci'
1586 h1c
1586 h1c
1587 b
1587 b
1588 a
1588 a
1589
1590 Test string escaping:
1591
1592 $ hg log -R latesttag -r 0 --template '>\n<>\\n<{if(rev, "[>\n<>\\n<]")}>\n<>\\n<\n'
1593 >
1594 <>\n<[>
1595 <>\n<]>
1596 <>\n<
General Comments 0
You need to be logged in to leave comments. Login now