Skip to content

Commit

Permalink
[gfm] only do backtracking (extended autolink path validation) for ww…
Browse files Browse the repository at this point in the history
…w or http autolinks
  • Loading branch information
Feder1co5oave committed Sep 18, 2018
1 parent 33408b9 commit 8117b56
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,22 +705,23 @@ InlineLexer.prototype.output = function(src) {

// url (gfm)
if (!this.inLink && (cap = this.rules.url.exec(src))) {
do {
prevCapZero = cap[0];
cap[0] = this.rules._backpedal.exec(cap[0])[0];
} while (prevCapZero !== cap[0]);
src = src.substring(cap[0].length);
if (cap[2] === '@') {
text = escape(cap[0]);
href = 'mailto:' + text;
} else {
// do extended autolink path validation
do {
prevCapZero = cap[0];
cap[0] = this.rules._backpedal.exec(cap[0])[0];
} while (prevCapZero !== cap[0]);
text = escape(cap[0]);
if (cap[1] === 'www.') {
href = 'http://' + text;
} else {
href = text;
}
}
src = src.substring(cap[0].length);
out += this.renderer.link(href, null, text);
continue;
}
Expand Down

0 comments on commit 8117b56

Please sign in to comment.