dont double escape certain entities/character references, fix encoding test

This commit is contained in:
Christopher Jeffrey 2011-11-30 07:31:25 -06:00
parent 9ab262b2cd
commit b702e91a10
3 changed files with 13 additions and 16 deletions

View File

@ -332,7 +332,7 @@ inline.lexer = function(str) {
if (cap = inline.code.exec(str)) { if (cap = inline.code.exec(str)) {
str = str.substring(cap[0].length); str = str.substring(cap[0].length);
out += '<code>' out += '<code>'
+ escape(cap[2] || cap[1]) + escape(cap[2] || cap[1], true)
+ '</code>'; + '</code>';
continue; continue;
} }
@ -413,7 +413,7 @@ var tok = function() {
} }
case 'code': { case 'code': {
return '<pre><code>' return '<pre><code>'
+ escape(token.text) + escape(token.text, true)
+ '</code></pre>'; + '</code></pre>';
} }
case 'blockquote_start': { case 'blockquote_start': {
@ -508,9 +508,11 @@ var parse = function(src) {
* Helpers * Helpers
*/ */
var escape = function(html) { var escape = function(html, dbl) {
return html return html
.replace(/&/g, '&amp;') .replace(!dbl
? /&(?!#?\w+;)/g
: /&/g, '&amp;')
.replace(/</g, '&lt;') .replace(/</g, '&lt;')
.replace(/>/g, '&gt;') .replace(/>/g, '&gt;')
.replace(/"/g, '&quot;') .replace(/"/g, '&quot;')

View File

@ -51,16 +51,11 @@ fs.readdirSync(dir).forEach(function(file) {
fs.writeFileSync(file, text); fs.writeFileSync(file, text);
}); });
// markdown avoids double encoding half of the time // markdown is weird with encoding
// and does it the other half. this behavior will be
// implemented eventually, but for now, this needs to
// be changed, because i want to see if the other tests
// included in this file pass.
(function() { (function() {
var file = dir + '/amps_and_angles_encoding.html'; var file = dir + '/amps_and_angles_encoding.html';
var html = fs.readFileSync(file, 'utf8') var html = fs.readFileSync(file, 'utf8')
.replace('6 > 5.', '6 &gt; 5.') .replace('6 > 5.', '6 &gt; 5.')
.replace('AT&amp;T is another', 'AT&amp;amp;T is another');
fs.writeFileSync(file, html); fs.writeFileSync(file, html);
})(); })();

View File

@ -1,6 +1,6 @@
<p>AT&amp;T has an ampersand in their name.</p> <p>AT&amp;T has an ampersand in their name.</p>
<p>AT&amp;amp;T is another way to write it.</p> <p>AT&amp;T is another way to write it.</p>
<p>This &amp; that.</p> <p>This &amp; that.</p>