Skip to content

Commit

Permalink
Strict escaping of ampersands
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Jun 12, 2012
1 parent cae4fd5 commit b8a14ea
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mustache.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
};

function escapeHtml(string) {
return String(string).replace(/&(?!\w+;)|[<>"']/g, function (s) {
return String(string).replace(/[&<>"']/g, function (s) {
return entityMap[s];
});
}
Expand Down
4 changes: 2 additions & 2 deletions test/_files/dot_notation.mustache
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!-- exciting part -->
<h1>{{name}}</h1>
<p>Authors: <ul>{{#authors}}<li>{{.}}</li>{{/authors}}</ul></p>
<p>Price: {{price.currency.symbol}}{{price.value}} {{#price.currency}}{{name}} <b>{{availability.text}}</b>{{/price.currency}}</p>
<p>VAT: {{price.currency.symbol}}{{#price}}{{vat}}{{/price}}</p>
<p>Price: {{{price.currency.symbol}}}{{price.value}} {{#price.currency}}{{name}} <b>{{availability.text}}</b>{{/price.currency}}</p>
<p>VAT: {{{price.currency.symbol}}}{{#price}}{{vat}}{{/price}}</p>
<!-- boring part -->
<h2>Test truthy false values:</h2>
<p>Zero: {{truthy.zero}}</p>
Expand Down
2 changes: 1 addition & 1 deletion test/_files/escaped.mustache
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<h1>{{title}}</h1>
But not {{entities}}.
And even {{entities}}, but not {{{entities}}}.
2 changes: 1 addition & 1 deletion test/_files/escaped.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<h1>Bear &gt; Shark</h1>
But not &quot;.
And even &amp;quot;, but not &quot;.

0 comments on commit b8a14ea

Please sign in to comment.