Skip to content

Commit

Permalink
Underscore 0.5.4 -- bugfix for single quotes in _.template strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Jan 5, 2010
1 parent fde8b1f commit 0a8a483
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
11 changes: 9 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ <h2>Downloads <i style="padding-left: 12px; font-size:12px;">(Right-click, and u
<p>
<table>
<tr>
<td><a href="underscore.js">Development Version (0.5.3)</a></td>
<td><a href="underscore.js">Development Version (0.5.4)</a></td>
<td><i>22kb, Uncompressed with Comments</i></td>
</tr>
<tr>
<td><a href="underscore-min.js">Production Version (0.5.3)</a></td>
<td><a href="underscore-min.js">Production Version (0.5.4)</a></td>
<td><i>3kb, Packed and Gzipped</i></td>
</tr>
</table>
Expand Down Expand Up @@ -1067,6 +1067,13 @@ <h2>Links &amp; Suggested Reading</h2>

<h2>Change Log</h2>

<p>
<b class="header">0.5.4</b><br />
Fix for multiple single quotes within a template string for
<tt>_.template</tt>. See:
<a href="http://www.west-wind.com/Weblog/posts/509108.aspx">Rick Strahl's blog post</a>.
</p>

<p>
<b class="header">0.5.2</b><br />
New implementations of <tt>isArray</tt>, <tt>isDate</tt>, <tt>isFunction</tt>,
Expand Down
4 changes: 2 additions & 2 deletions underscore-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
propertyIsEnumerable = Object.prototype.propertyIsEnumerable;

// Current version.
_.VERSION = '0.5.3';
_.VERSION = '0.5.4';

// ------------------------ Collection Functions: ---------------------------

Expand Down Expand Up @@ -561,19 +561,19 @@

// JavaScript templating a-la ERB, pilfered from John Resig's
// "Secrets of the JavaScript Ninja", page 83.
// Single-quote fix from Rick Strahl's version.
_.template = function(str, data) {
var fn = new Function('obj',
'var p=[],print=function(){p.push.apply(p,arguments);};' +
'with(obj){p.push(\'' +
str
.replace(/[\r\t\n]/g, " ")
.split("<%").join("\t")
.replace(/((^|%>)[^\t]*)'/g, "$1\r")
.replace(/\t=(.*?)%>/g, "',$1,'")
.split("\t").join("');")
.split("%>").join("p.push('")
.split("\r").join("\\'")
+ "');}return p.join('');");
str.replace(/[\r\t\n]/g, " ")
.replace(/'(?=[^%]*%>)/g,"\t")
.split("'").join("\\'")
.split("\t").join("'")
.replace(/<%=(.+?)%>/g, "',$1,'")
.split("<%").join("');")
.split("%>").join("p.push('")
+ "');}return p.join('');");
return data ? fn(data) : fn;
};

Expand Down

0 comments on commit 0a8a483

Please sign in to comment.