Skip to content

Commit 34ebd1c

Browse files
committed
Merge pull request #530 from janl/improve-html-escaping
Improve HTML escaping
2 parents 53b1c95 + 378bcca commit 34ebd1c

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

mustache.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@
6363
'>': '>',
6464
'"': '"',
6565
"'": ''',
66-
'/': '/'
66+
'/': '/',
67+
'`': '`',
68+
'=': '='
6769
};
6870

6971
function escapeHtml (string) {
70-
return String(string).replace(/[&<>"'\/]/g, function fromEntityMap (s) {
72+
return String(string).replace(/[&<>"'`=\/]/g, function fromEntityMap (s) {
7173
return entityMap[s];
7274
});
7375
}

test/_files/escaped.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
title: function () {
33
return "Bear > Shark";
44
},
5-
entities: "&quot; \"'<>/"
5+
entities: "&quot; \"'<>`=/"
66
})

test/_files/escaped.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<h1>Bear &gt; Shark</h1>
2-
And even &amp;quot; &quot;&#39;&lt;&gt;&#x2F;, but not &quot; "'<>/.
2+
And even &amp;quot; &quot;&#39;&lt;&gt;&#x60;&#x3D;&#x2F;, but not &quot; "'<>`=/.

0 commit comments

Comments
 (0)