mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 01:47:48 +00:00
Merge pull request #401 from Stuk/template_js_fix
Fix escaped chars in Javascript in templates
This commit is contained in:
@@ -63,6 +63,10 @@ $(document).ready(function() {
|
|||||||
result = fancyTemplate({people : {moe : "Moe", larry : "Larry", curly : "Curly"}});
|
result = fancyTemplate({people : {moe : "Moe", larry : "Larry", curly : "Curly"}});
|
||||||
equals(result, "<ul><li>Moe</li><li>Larry</li><li>Curly</li></ul>", 'can run arbitrary javascript in templates');
|
equals(result, "<ul><li>Moe</li><li>Larry</li><li>Curly</li></ul>", 'can run arbitrary javascript in templates');
|
||||||
|
|
||||||
|
var escapedCharsInJavascriptTemplate = _.template("<ul><% _.each(numbers.split('\\n'), function(item) { %><li><%= item %></li><% }) %></ul>");
|
||||||
|
result = escapedCharsInJavascriptTemplate({numbers: "one\ntwo\nthree\nfour"});
|
||||||
|
equals(result, "<ul><li>one</li><li>two</li><li>three</li><li>four</li></ul>", 'Can use escaped characters (e.g. \\n) in Javascript')
|
||||||
|
|
||||||
var namespaceCollisionTemplate = _.template("<%= pageCount %> <%= thumbnails[pageCount] %> <% _.each(thumbnails, function(p) { %><div class=\"thumbnail\" rel=\"<%= p %>\"></div><% }); %>");
|
var namespaceCollisionTemplate = _.template("<%= pageCount %> <%= thumbnails[pageCount] %> <% _.each(thumbnails, function(p) { %><div class=\"thumbnail\" rel=\"<%= p %>\"></div><% }); %>");
|
||||||
result = namespaceCollisionTemplate({
|
result = namespaceCollisionTemplate({
|
||||||
pageCount: 3,
|
pageCount: 3,
|
||||||
|
|||||||
@@ -910,7 +910,8 @@
|
|||||||
})
|
})
|
||||||
.replace(c.evaluate || null, function(match, code) {
|
.replace(c.evaluate || null, function(match, code) {
|
||||||
return "');" + code.replace(/\\'/g, "'")
|
return "');" + code.replace(/\\'/g, "'")
|
||||||
.replace(/[\r\n\t]/g, ' ') + ";__p.push('";
|
.replace(/[\r\n\t]/g, ' ')
|
||||||
|
.replace(/\\\\/g, '\\') + ";__p.push('";
|
||||||
})
|
})
|
||||||
.replace(/\r/g, '\\r')
|
.replace(/\r/g, '\\r')
|
||||||
.replace(/\n/g, '\\n')
|
.replace(/\n/g, '\\n')
|
||||||
|
|||||||
Reference in New Issue
Block a user