From 8117b56a2ec00b99f35b2dac4c272b5ab741efdf Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Tue, 18 Sep 2018 21:34:10 +0200 Subject: [PATCH] [gfm] only do backtracking (extended autolink path validation) for www or http autolinks --- lib/marked.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index 85e2ebabe3..d635f2449e 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -705,15 +705,15 @@ 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; @@ -721,6 +721,7 @@ InlineLexer.prototype.output = function(src) { href = text; } } + src = src.substring(cap[0].length); out += this.renderer.link(href, null, text); continue; }