Skip to content

Commit a3cddee

Browse files
committed
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.
1 parent 666e455 commit a3cddee

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

lib/marked.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,8 @@ InlineLexer.prototype.output = function(src) {
655655
text,
656656
href,
657657
title,
658-
cap;
658+
cap,
659+
prevCapZero;
659660

660661
while (src) {
661662
// escape
@@ -681,7 +682,10 @@ InlineLexer.prototype.output = function(src) {
681682

682683
// url (gfm)
683684
if (!this.inLink && (cap = this.rules.url.exec(src))) {
684-
cap[0] = this.rules._backpedal.exec(cap[0])[0];
685+
do {
686+
prevCapZero = cap[0];
687+
cap[0] = this.rules._backpedal.exec(cap[0])[0];
688+
} while (prevCapZero !== cap[0]);
685689
src = src.substring(cap[0].length);
686690
if (cap[2] === '@') {
687691
text = escape(cap[0]);

test/specs/marked/marked-spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ Messenger.prototype.test = function(spec, section, ignore) {
3232

3333
var messenger = new Messenger();
3434

35+
describe('Marked Autolinks', function() {
36+
var section = 'Autolinks';
37+
38+
// var shouldPassButFails = [];
39+
var shouldPassButFails = [];
40+
41+
var willNotBeAttemptedByCoreTeam = [];
42+
43+
var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);
44+
45+
markedSpec.forEach(function(spec) {
46+
messenger.test(spec, section, ignore);
47+
});
48+
});
49+
3550
describe('Marked Code spans', function() {
3651
var section = 'Code spans';
3752

test/specs/marked/marked.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
[
2+
{
3+
"section": "Autolinks",
4+
"markdown": "(See https://www.example.com/fhqwhgads.)",
5+
"html": "<p>(See <a href=\"https://www.example.com/fhqwhgads\">https://www.example.com/fhqwhgads</a>.)</p>",
6+
"example": 10
7+
},
28
{
39
"section": "Code spans",
410
"markdown": "`[email protected]`",

0 commit comments

Comments
 (0)