From b1651b1363a3ad3a438e3db502ed886efd71c9ed Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Fri, 20 Nov 2020 19:27:16 +0300 Subject: [PATCH] Stop link title parsing when second `(` is found `[](url (xxx())` is no longer a valid link --- CHANGELOG.md | 1 + lib/helpers/parse_link_title.js | 2 ++ test/fixtures/markdown-it/commonmark_extras.txt | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d72b27..ffb505a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [12.0.3] - WIP ### Fixed - `[]()` is no longer a valid link. +- `[](url (xxx())` is no longer a valid link. - Fix performance issues when parsing links, #732. - Fix performance issues when parsing backticks, #733. diff --git a/lib/helpers/parse_link_title.js b/lib/helpers/parse_link_title.js index 0d66d23..051d6f4 100644 --- a/lib/helpers/parse_link_title.js +++ b/lib/helpers/parse_link_title.js @@ -37,6 +37,8 @@ module.exports = function parseLinkTitle(str, pos, max) { result.str = unescapeAll(str.slice(start + 1, pos)); result.ok = true; return result; + } else if (code === 0x28 /* ( */ && marker === 0x29 /* ) */) { + return result; } else if (code === 0x0A) { lines++; } else if (code === 0x5C /* \ */ && pos + 1 < max) { diff --git a/test/fixtures/markdown-it/commonmark_extras.txt b/test/fixtures/markdown-it/commonmark_extras.txt index d82d8d5..2cb2e69 100644 --- a/test/fixtures/markdown-it/commonmark_extras.txt +++ b/test/fixtures/markdown-it/commonmark_extras.txt @@ -267,6 +267,17 @@ Link destination cannot contain '<' . +Link title cannot contain '(' when opened with it +. +[](url (xxx()) + +[](url (xxx\()) +. +

[](url (xxx())

+

+. + + Coverage. Directive can terminate paragraph. . a