From 1198c5b1c9296f284ac83a0931f52f2b964c393e Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Thu, 19 Nov 2020 16:49:14 +0300 Subject: [PATCH] Fix performance issues when parsing links close https://github.com/markdown-it/markdown-it/issues/732 --- lib/helpers/parse_link_destination.js | 2 ++ test/fixtures/markdown-it/commonmark_extras.txt | 12 ++++++++++++ test/pathological.js | 4 ++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/helpers/parse_link_destination.js b/lib/helpers/parse_link_destination.js index 10953b645..6c1423c6a 100644 --- a/lib/helpers/parse_link_destination.js +++ b/lib/helpers/parse_link_destination.js @@ -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)); @@ -58,6 +59,7 @@ module.exports = function parseLinkDestination(str, pos, max) { if (code === 0x28 /* ( */) { level++; + if (level > 32) { return result; } } if (code === 0x29 /* ) */) { diff --git a/test/fixtures/markdown-it/commonmark_extras.txt b/test/fixtures/markdown-it/commonmark_extras.txt index 4cda25712..d82d8d50f 100644 --- a/test/fixtures/markdown-it/commonmark_extras.txt +++ b/test/fixtures/markdown-it/commonmark_extras.txt @@ -255,6 +255,18 @@ List item terminating quote should not be paragraph continuation . + +Link destination cannot contain '<' +. +[]() + +[]() +. +

[](<foo)

+

+. + + Coverage. Directive can terminate paragraph. . a diff --git a/test/pathological.js b/test/pathological.js index 5ae258819..7e9991a9f 100644 --- a/test/pathological.js +++ b/test/pathological.js @@ -121,14 +121,14 @@ describe('Pathological', function () { ); }); - it.skip('unclosed links A', function () { + it('unclosed links A', function () { assert.match( md.render('[a](