Przeglądaj źródła

Strict HTML escape.

This replaces the soft escaping ('&' -> '&') with strict escaping ('&' -> '&'). This new behavior matches that of Ruby and other Mustache implementations.

Other points:
- `dot_notation` currency is changed to use an ASCII character, since the JS interpreters did not appreciate unicode.
- Forward slash is added to escape list c/o OWASP recommendations.
tags/0.5.2
Chad Weider 14 lat temu
rodzic
commit
e2d919a214
5 zmienionych plików z 9 dodań i 8 usunięć
  1. +3
    -2
      mustache.js
  2. +2
    -2
      spec/_files/dot_notation.js
  3. +2
    -2
      spec/_files/dot_notation.txt
  4. +1
    -1
      spec/_files/escaped.js
  5. +1
    -1
      spec/_files/escaped.txt

+ 3
- 2
mustache.js Wyświetl plik

@@ -86,11 +86,12 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
"<": "&lt;", "<": "&lt;",
">": "&gt;", ">": "&gt;",
'"': '&quot;', '"': '&quot;',
"'": '&#39;'
"'": '&#39;',
"/": '&#x2F;'
}; };


function escapeHTML(string) { function escapeHTML(string) {
return String(string).replace(/&(?!\w+;)|[<>"']/g, function (s) {
return String(string).replace(/[&<>"'\/]/g, function (s) {
return escapeMap[s] || s; return escapeMap[s] || s;
}); });
} }


+ 2
- 2
spec/_files/dot_notation.js Wyświetl plik

@@ -7,8 +7,8 @@ var dot_notation = {
return this.value * 0.2; return this.value * 0.2;
}, },
currency: { currency: {
symbol: '&euro;',
name: 'Euro'
symbol: '$',
name: 'USD'
} }
}, },
availability:{ availability:{


+ 2
- 2
spec/_files/dot_notation.txt Wyświetl plik

@@ -1,8 +1,8 @@
<!-- exciting part --> <!-- exciting part -->
<h1>A Book</h1> <h1>A Book</h1>
<p>Authors: <ul><li>John Power</li><li>Jamie Walsh</li></ul></p> <p>Authors: <ul><li>John Power</li><li>Jamie Walsh</li></ul></p>
<p>Price: &euro;200 Euro <b>In Stock</b></p>
<p>VAT: &euro;40</p>
<p>Price: $200 USD <b>In Stock</b></p>
<p>VAT: $40</p>
<!-- boring part --> <!-- boring part -->
<h2>Test truthy false values:</h2> <h2>Test truthy false values:</h2>
<p>Zero: 0</p> <p>Zero: 0</p>


+ 1
- 1
spec/_files/escaped.js Wyświetl plik

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

+ 1
- 1
spec/_files/escaped.txt Wyświetl plik

@@ -1,2 +1,2 @@
<h1>Bear &gt; Shark</h1> <h1>Bear &gt; Shark</h1>
But not &quot;.
But not &amp;quot; &quot;&#39;&lt;&gt;&#x2F;.

Ładowanie…
Anuluj
Zapisz