Kaynağa Gözat

Merge pull request #530 from janl/improve-html-escaping

Improve HTML escaping
tags/v2.2.1
David da Silva 10 yıl önce
ebeveyn
işleme
34ebd1cb1a
3 değiştirilmiş dosya ile 6 ekleme ve 4 silme
  1. +4
    -2
      mustache.js
  2. +1
    -1
      test/_files/escaped.js
  3. +1
    -1
      test/_files/escaped.txt

+ 4
- 2
mustache.js Dosyayı Görüntüle

@@ -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];
});
}


+ 1
- 1
test/_files/escaped.js Dosyayı Görüntüle

@@ -2,5 +2,5 @@
title: function () {
return "Bear > Shark";
},
entities: "&quot; \"'<>/"
entities: "&quot; \"'<>`=/"
})

+ 1
- 1
test/_files/escaped.txt Dosyayı Görüntüle

@@ -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; "'<>`=/.

Yükleniyor…
İptal
Kaydet