From a3cddeeae61063d6727e246aaa92662a0a6bc791 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 22 Jun 2018 13:51:48 -0700 Subject: [PATCH 1/3] fix gfm extended autolinking requiring multiple backpedals Add a test and fix that trailing punctuation is omitted in link URLs for markdown like this: (See https://www.example.com/fhqwhgads.) The trailing period and closing parenthesis should not be part of the link URL. --- lib/marked.js | 8 ++++++-- test/specs/marked/marked-spec.js | 15 +++++++++++++++ test/specs/marked/marked.json | 6 ++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index 81c482d41c..74aafc3552 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -655,7 +655,8 @@ InlineLexer.prototype.output = function(src) { text, href, title, - cap; + cap, + prevCapZero; while (src) { // escape @@ -681,7 +682,10 @@ InlineLexer.prototype.output = function(src) { // url (gfm) if (!this.inLink && (cap = this.rules.url.exec(src))) { - cap[0] = this.rules._backpedal.exec(cap[0])[0]; + 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]); diff --git a/test/specs/marked/marked-spec.js b/test/specs/marked/marked-spec.js index 5d4d32e91c..8b8cb5ee45 100644 --- a/test/specs/marked/marked-spec.js +++ b/test/specs/marked/marked-spec.js @@ -32,6 +32,21 @@ Messenger.prototype.test = function(spec, section, ignore) { var messenger = new Messenger(); +describe('Marked Autolinks', function() { + var section = 'Autolinks'; + + // var shouldPassButFails = []; + var shouldPassButFails = []; + + var willNotBeAttemptedByCoreTeam = []; + + var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam); + + markedSpec.forEach(function(spec) { + messenger.test(spec, section, ignore); + }); +}); + describe('Marked Code spans', function() { var section = 'Code spans'; diff --git a/test/specs/marked/marked.json b/test/specs/marked/marked.json index 60c2023827..bb3943bb91 100644 --- a/test/specs/marked/marked.json +++ b/test/specs/marked/marked.json @@ -1,4 +1,10 @@ [ + { + "section": "Autolinks", + "markdown": "(See https://www.example.com/fhqwhgads.)", + "html": "

(See https://www.example.com/fhqwhgads.)

", + "example": 10 + }, { "section": "Code spans", "markdown": "`someone@example.com`", From 3eeb0df963f73a1cfe2d2c093bb89ef143851dec Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 26 Jun 2018 22:45:55 -0700 Subject: [PATCH 2/3] squash! remove unnecessary commented-out code --- test/specs/marked/marked-spec.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/specs/marked/marked-spec.js b/test/specs/marked/marked-spec.js index 8b8cb5ee45..182cebcda7 100644 --- a/test/specs/marked/marked-spec.js +++ b/test/specs/marked/marked-spec.js @@ -35,7 +35,6 @@ var messenger = new Messenger(); describe('Marked Autolinks', function() { var section = 'Autolinks'; - // var shouldPassButFails = []; var shouldPassButFails = []; var willNotBeAttemptedByCoreTeam = []; @@ -50,7 +49,6 @@ describe('Marked Autolinks', function() { describe('Marked Code spans', function() { var section = 'Code spans'; - // var shouldPassButFails = []; var shouldPassButFails = [1]; var willNotBeAttemptedByCoreTeam = []; @@ -65,7 +63,6 @@ describe('Marked Code spans', function() { describe('Marked Table cells', function() { var section = 'Table cells'; - // var shouldPassButFails = []; var shouldPassButFails = []; var willNotBeAttemptedByCoreTeam = []; From 40bf2e6511c1c7bacdbda31695add40725879780 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 26 Jun 2018 22:50:15 -0700 Subject: [PATCH 3/3] squash! more tests --- test/specs/marked/marked.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/specs/marked/marked.json b/test/specs/marked/marked.json index bb3943bb91..219f36b451 100644 --- a/test/specs/marked/marked.json +++ b/test/specs/marked/marked.json @@ -5,6 +5,18 @@ "html": "

(See https://www.example.com/fhqwhgads.)

", "example": 10 }, + { + "section": "Autolinks", + "markdown": "((http://foo.com))", + "html": "

((http://foo.com))

", + "example": 11 + }, + { + "section": "Autolinks", + "markdown": "((http://foo.com.))", + "html": "

((http://foo.com.))

", + "example": 12 + }, { "section": "Code spans", "markdown": "`someone@example.com`",