From 2290e109c5c6b0391f4416adc9c0b0a9b9923326 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Tue, 24 Nov 2020 14:43:32 +0300 Subject: [PATCH] Disallow escaped spaces inside link destination --- CHANGELOG.md | 1 + lib/helpers/parse_link_destination.js | 1 + test/fixtures/markdown-it/commonmark_extras.txt | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b45a881e7..45e4e5c03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - `[]()` is no longer a valid link. - `[](url (xxx())` is no longer a valid link. +- `[](url\ xxx)` is no longer a valid link. - Fix performance issues when parsing links, #732, #734. - Fix performance issues when parsing backticks, #733. - Fix performance issues when parsing emphases, #735. diff --git a/lib/helpers/parse_link_destination.js b/lib/helpers/parse_link_destination.js index 6c1423c6a..637f1f42e 100644 --- a/lib/helpers/parse_link_destination.js +++ b/lib/helpers/parse_link_destination.js @@ -53,6 +53,7 @@ module.exports = function parseLinkDestination(str, pos, max) { if (code < 0x20 || code === 0x7F) { break; } if (code === 0x5C /* \ */ && pos + 1 < max) { + if (str.charCodeAt(pos + 1) === 0x20) { break; } pos += 2; continue; } diff --git a/test/fixtures/markdown-it/commonmark_extras.txt b/test/fixtures/markdown-it/commonmark_extras.txt index 75a9fecb0..56b4a31bc 100644 --- a/test/fixtures/markdown-it/commonmark_extras.txt +++ b/test/fixtures/markdown-it/commonmark_extras.txt @@ -278,6 +278,14 @@ Link title cannot contain '(' when opened with it . +Escaped space is not allowed in link destination, commonmark/CommonMark#493. +. +[link](a\ b) +. +

[link](a\ b)

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