Skip to content

Commit

Permalink
Merge pull request #530 from janl/improve-html-escaping
Browse files Browse the repository at this point in the history
Improve HTML escaping
  • Loading branch information
dasilvacontin committed Nov 23, 2015
2 parents 53b1c95 + 378bcca commit 34ebd1c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions mustache.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@
'>': '>',
'"': '"',
"'": ''',
'/': '/'
'/': '/',
'`': '`',
'=': '='
};

function escapeHtml (string) {
return String(string).replace(/[&<>"'\/]/g, function fromEntityMap (s) {
return String(string).replace(/[&<>"'`=\/]/g, function fromEntityMap (s) {
return entityMap[s];
});
}
Expand Down
2 changes: 1 addition & 1 deletion test/_files/escaped.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
title: function () {
return "Bear > Shark";
},
entities: "&quot; \"'<>/"
entities: "&quot; \"'<>`=/"
})
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>
And even &amp;quot; &quot;&#39;&lt;&gt;&#x2F;, but not &quot; "'<>/.
And even &amp;quot; &quot;&#39;&lt;&gt;&#x60;&#x3D;&#x2F;, but not &quot; "'<>`=/.

0 comments on commit 34ebd1c

Please sign in to comment.