Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix gfm extended autolinking requiring multiple backpedals #1293

Merged
merged 3 commits into from
Jul 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,8 @@ InlineLexer.prototype.output = function(src) {
text,
href,
title,
cap;
cap,
prevCapZero;

while (src) {
// escape
Expand All @@ -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]);
Expand Down
16 changes: 14 additions & 2 deletions test/specs/marked/marked-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,23 @@ Messenger.prototype.test = function(spec, section, ignore) {

var messenger = new Messenger();

describe('Marked Autolinks', function() {
var section = 'Autolinks';

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';

// var shouldPassButFails = [];
var shouldPassButFails = [1];

var willNotBeAttemptedByCoreTeam = [];
Expand All @@ -50,7 +63,6 @@ describe('Marked Code spans', function() {
describe('Marked Table cells', function() {
var section = 'Table cells';

// var shouldPassButFails = [];
var shouldPassButFails = [];

var willNotBeAttemptedByCoreTeam = [];
Expand Down
18 changes: 18 additions & 0 deletions test/specs/marked/marked.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
[
{
"section": "Autolinks",
"markdown": "(See https://www.example.com/fhqwhgads.)",
"html": "<p>(See <a href=\"https://www.example.com/fhqwhgads\">https://www.example.com/fhqwhgads</a>.)</p>",
"example": 10
},
{
"section": "Autolinks",
"markdown": "((http://foo.com))",
"html": "<p>((<a href=\"http://foo.com\">http://foo.com</a>))</p>",
"example": 11
},
{
"section": "Autolinks",
"markdown": "((http://foo.com.))",
"html": "<p>((<a href=\"http://foo.com\">http://foo.com</a>.))</p>",
"example": 12
},
{
"section": "Code spans",
"markdown": "`someone@example.com`",
Expand Down