diff --git a/README b/README index b7baba233..716757d52 100644 --- a/README +++ b/README @@ -31,3 +31,4 @@ Many thanks to our contributors: Luke Sutton Ryan Tenney John Wright + Samuel Clay diff --git a/test/utility.js b/test/utility.js index 8670a9fda..0b07b9fd1 100644 --- a/test/utility.js +++ b/test/utility.js @@ -58,6 +58,17 @@ $(document).ready(function() { var fancyTemplate = _.template(""); result = fancyTemplate({people : {moe : "Moe", larry : "Larry", curly : "Curly"}}); equals(result, "", 'can run arbitrary javascript in templates'); + + var namespaceCollisionTemplate = _.template("<%= pageCount %> <%= thumbnails[pageCount] %> <% _.each(thumbnails, function(p) { %>
\" />
<% }); %>"); + result = namespaceCollisionTemplate({ + pageCount: 3, + thumbnails: { + 1: "p1-thumbnail.gif", + 2: "p2-thumbnail.gif", + 3: "p3-thumbnail.gif" + } + }); + equals(result, "3 p3-thumbnail.gif
"); var noInterpolateTemplate = _.template("

Just some text. Hey, I know this is silly but it aids consistency.

"); result = noInterpolateTemplate(); diff --git a/underscore.js b/underscore.js index c20514ca9..6b77e3469 100644 --- a/underscore.js +++ b/underscore.js @@ -630,8 +630,8 @@ var c = _.templateSettings; var endMatch = new RegExp("'(?=[^"+c.end.substr(0, 1)+"]*"+escapeRegExp(c.end)+")","g"); var fn = new Function('obj', - 'var p=[],print=function(){p.push.apply(p,arguments);};' + - 'with(obj||{}){p.push(\'' + + 'var __p=[],print=function(){__p.push.apply(__p,arguments);};' + + 'with(obj||{}){__p.push(\'' + str.replace(/\r/g, '\\r') .replace(/\n/g, '\\n') .replace(/\t/g, '\\t') @@ -640,8 +640,8 @@ .split("✄").join("'") .replace(c.interpolate, "',$1,'") .split(c.start).join("');") - .split(c.end).join("p.push('") - + "');}return p.join('');"); + .split(c.end).join("__p.push('") + + "');}return __p.join('');"); return data ? fn(data) : fn; };