Skip to content

Commit c89b35c

Browse files
committed
html renderer: Don't preserve entities when rendering...
href, src, title, info string. This gives rise to double-encoding errors, when the original markdown is e.g. `:`, since the commonmark reader already unescapes entities. Thanks to Sebastiaan Knijnenburg for noticing this.
1 parent 5181f25 commit c89b35c

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

lib/render/html.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ function link(node, entering) {
6262
var attrs = this.attrs(node);
6363
if (entering) {
6464
if (!(this.options.safe && potentiallyUnsafe(node.destination))) {
65-
attrs.push(['href', this.esc(node.destination, true)]);
65+
attrs.push(['href', this.esc(node.destination, false)]);
6666
}
6767
if (node.title) {
68-
attrs.push(['title', this.esc(node.title, true)]);
68+
attrs.push(['title', this.esc(node.title, false)]);
6969
}
7070
this.tag('a', attrs);
7171
} else {
@@ -79,7 +79,7 @@ function image(node, entering) {
7979
if (this.options.safe && potentiallyUnsafe(node.destination)) {
8080
this.lit('<img src="" alt="');
8181
} else {
82-
this.lit('<img src="' + this.esc(node.destination, true) +
82+
this.lit('<img src="' + this.esc(node.destination, false) +
8383
'" alt="');
8484
}
8585
}
@@ -88,7 +88,7 @@ function image(node, entering) {
8888
this.disableTags -= 1;
8989
if (this.disableTags === 0) {
9090
if (node.title) {
91-
this.lit('" title="' + this.esc(node.title, true));
91+
this.lit('" title="' + this.esc(node.title, false));
9292
}
9393
this.lit('" />');
9494
}
@@ -143,7 +143,7 @@ function code_block(node) {
143143
var info_words = node.info ? node.info.split(/\s+/) : []
144144
, attrs = this.attrs(node);
145145
if (info_words.length > 0 && info_words[0].length > 0) {
146-
attrs.push(['class', 'language-' + this.esc(info_words[0], true)]);
146+
attrs.push(['class', 'language-' + this.esc(info_words[0], false)]);
147147
}
148148
this.cr();
149149
this.tag('pre');

test/regression.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ Issue #116 - tabs before and after ATX closing heading
9595
<h1>foo</h1>
9696
````````````````````````````````
9797

98-
commonmark/CommonMark#493 - escaped space not allowed in link
99-
destination.
98+
commonmark/CommonMark#493 - escaped space not allowed in link destination.
99+
100100
```````````````````````````````` example
101101
[link](a\ b)
102102
.
@@ -116,3 +116,11 @@ City:
116116
<meta itemprop="name" content="Springfield">
117117
</span></p>
118118
````````````````````````````````
119+
120+
Double-encoding.
121+
122+
```````````````````````````````` example
123+
[XSS](javascript&amp;colon;alert%28&#039;XSS&#039;%29)
124+
.
125+
<p><a href="javascript&amp;colon;alert('XSS')">XSS</a></p>
126+
````````````````````````````````

0 commit comments

Comments
 (0)