mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 20:07:49 +00:00
Fixing _.template() bug where using 'p' as a variable name would override the variable by the same name in _.template(), causing an error. See test case utilities.namespaceCollisionTemplate() for example of broken case.
This commit is contained in:
1
README
1
README
@@ -31,3 +31,4 @@ Many thanks to our contributors:
|
|||||||
Luke Sutton
|
Luke Sutton
|
||||||
Ryan Tenney
|
Ryan Tenney
|
||||||
John Wright
|
John Wright
|
||||||
|
Samuel Clay
|
||||||
|
|||||||
@@ -59,6 +59,17 @@ $(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 namespaceCollisionTemplate = _.template("<%= pageCount %> <%= thumbnails[pageCount] %> <% _.each(thumbnails, function(p) { %><div class=\"DV-thumbnail\"><img src=\"<%= p %>\" /></div><% }); %>");
|
||||||
|
result = namespaceCollisionTemplate({
|
||||||
|
pageCount: 3,
|
||||||
|
thumbnails: {
|
||||||
|
1: "p1-thumbnail.gif",
|
||||||
|
2: "p2-thumbnail.gif",
|
||||||
|
3: "p3-thumbnail.gif"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
equals(result, "3 p3-thumbnail.gif <div class=\"DV-thumbnail\"><img src=\"p1-thumbnail.gif\" /></div><div class=\"DV-thumbnail\"><img src=\"p2-thumbnail.gif\" /></div><div class=\"DV-thumbnail\"><img src=\"p3-thumbnail.gif\" /></div>");
|
||||||
|
|
||||||
var noInterpolateTemplate = _.template("<div><p>Just some text. Hey, I know this is silly but it aids consistency.</p></div>");
|
var noInterpolateTemplate = _.template("<div><p>Just some text. Hey, I know this is silly but it aids consistency.</p></div>");
|
||||||
result = noInterpolateTemplate();
|
result = noInterpolateTemplate();
|
||||||
equals(result, "<div><p>Just some text. Hey, I know this is silly but it aids consistency.</p></div>");
|
equals(result, "<div><p>Just some text. Hey, I know this is silly but it aids consistency.</p></div>");
|
||||||
|
|||||||
@@ -630,8 +630,8 @@
|
|||||||
var c = _.templateSettings;
|
var c = _.templateSettings;
|
||||||
var endMatch = new RegExp("'(?=[^"+c.end.substr(0, 1)+"]*"+escapeRegExp(c.end)+")","g");
|
var endMatch = new RegExp("'(?=[^"+c.end.substr(0, 1)+"]*"+escapeRegExp(c.end)+")","g");
|
||||||
var fn = new Function('obj',
|
var fn = new Function('obj',
|
||||||
'var p=[],print=function(){p.push.apply(p,arguments);};' +
|
'var __p=[],print=function(){__p.push.apply(__p,arguments);};' +
|
||||||
'with(obj||{}){p.push(\'' +
|
'with(obj||{}){__p.push(\'' +
|
||||||
str.replace(/\r/g, '\\r')
|
str.replace(/\r/g, '\\r')
|
||||||
.replace(/\n/g, '\\n')
|
.replace(/\n/g, '\\n')
|
||||||
.replace(/\t/g, '\\t')
|
.replace(/\t/g, '\\t')
|
||||||
@@ -640,8 +640,8 @@
|
|||||||
.split("✄").join("'")
|
.split("✄").join("'")
|
||||||
.replace(c.interpolate, "',$1,'")
|
.replace(c.interpolate, "',$1,'")
|
||||||
.split(c.start).join("');")
|
.split(c.start).join("');")
|
||||||
.split(c.end).join("p.push('")
|
.split(c.end).join("__p.push('")
|
||||||
+ "');}return p.join('');");
|
+ "');}return __p.join('');");
|
||||||
return data ? fn(data) : fn;
|
return data ? fn(data) : fn;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user