Skip to content

Commit

Permalink
Fix performance issues when parsing links
Browse files Browse the repository at this point in the history
close #732
  • Loading branch information
rlidwka committed Nov 19, 2020
1 parent 725a916 commit 1198c5b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/helpers/parse_link_destination.js
Expand Up @@ -22,6 +22,7 @@ module.exports = function parseLinkDestination(str, pos, max) {
while (pos < max) {
code = str.charCodeAt(pos);
if (code === 0x0A /* \n */) { return result; }
if (code === 0x3C /* < */) { return result; }
if (code === 0x3E /* > */) {
result.pos = pos + 1;
result.str = unescapeAll(str.slice(start + 1, pos));
Expand Down Expand Up @@ -58,6 +59,7 @@ module.exports = function parseLinkDestination(str, pos, max) {

if (code === 0x28 /* ( */) {
level++;
if (level > 32) { return result; }
}

if (code === 0x29 /* ) */) {
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/markdown-it/commonmark_extras.txt
Expand Up @@ -255,6 +255,18 @@ List item terminating quote should not be paragraph continuation
</ol>
.


Link destination cannot contain '<'
.
[](<foo<bar>)

[](<foo\<bar>)
.
<p>[](&lt;foo<bar>)</p>
<p><a href="foo%3Cbar"></a></p>
.


Coverage. Directive can terminate paragraph.
.
a
Expand Down
4 changes: 2 additions & 2 deletions test/pathological.js
Expand Up @@ -121,14 +121,14 @@ describe('Pathological', function () {
);
});

it.skip('unclosed links A', function () {
it('unclosed links A', function () {
assert.match(
md.render('[a](<b'.repeat(30000)),
/(\[a\]\(&lt;b){30000}/
);
});

it.skip('unclosed links B', function () {
it('unclosed links B', function () {
assert.match(
md.render('[a](b'.repeat(30000)),
/(\[a\]\(b){30000}/
Expand Down

0 comments on commit 1198c5b

Please sign in to comment.