Skip to content

Commit

Permalink
Fix matchStart for incomplete links
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka committed May 2, 2022
1 parent 95c261b commit d03a760
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
4.0.1 / WIP
------------------

- Fix `http://` incorrectly returned as a link by matchStart.


4.0.0 / 2022-04-22
------------------

Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,11 @@ LinkifyIt.prototype.matchAtStart = function matchAtStart(text) {
if (!m) return null;

var len = this.testSchemaAt(text, m[2], m[0].length);
if (len) {
this.__schema__ = m[2];
this.__index__ = m.index + m[1].length;
this.__last_index__ = m.index + m[0].length + len;
}
if (!len) return null;

this.__schema__ = m[2];
this.__index__ = m.index + m[1].length;
this.__last_index__ = m.index + m[0].length + len;

return createMatch(this, 0);
};
Expand Down
8 changes: 8 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,12 @@ describe('API', function () {
assert.ok(!l.matchAtStart(str));
assert.strictEqual(l.match(str).length, 2);
});

it('should not match incomplete links', function () {
// regression test for https://github.com/markdown-it/markdown-it/issues/868
var l = linkify();

assert.ok(!l.matchAtStart('http://'));
assert.ok(!l.matchAtStart('https://'));
});
});

0 comments on commit d03a760

Please sign in to comment.