From f156ed1bffec0e02b2353abf248c5b10c6101524 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Wed, 14 Oct 2020 16:18:17 +0300 Subject: [PATCH] Don't decode %25 in beautified urls fix https://github.com/markdown-it/markdown-it/issues/720 --- CHANGELOG.md | 1 + lib/index.js | 3 ++- test/fixtures/markdown-it/normalize.txt | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ab4ca7..faaa32d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fix mappings for table rows (amended fix made in 11.0.1), #705. +- `%25` is no longer decoded in beautified urls, #720. ## [11.0.1] - 2020-09-14 diff --git a/lib/index.js b/lib/index.js index 7ef807c..69d3daf 100644 --- a/lib/index.js +++ b/lib/index.js @@ -81,7 +81,8 @@ function normalizeLinkText(url) { } } - return mdurl.decode(mdurl.format(parsed)); + // add '%' to exclude list because of https://github.com/markdown-it/markdown-it/issues/720 + return mdurl.decode(mdurl.format(parsed), mdurl.decode.defaultChars + '%'); } diff --git a/test/fixtures/markdown-it/normalize.txt b/test/fixtures/markdown-it/normalize.txt index 14fa2a9..6faed59 100644 --- a/test/fixtures/markdown-it/normalize.txt +++ b/test/fixtures/markdown-it/normalize.txt @@ -13,6 +13,15 @@ Encode link destination, decode text inside it:

foo

. + +Keep %25 as is because decoding it may break urls, #720 +. + +. +

https://www.google.com/search?q=hello.%252Ehello

+. + + Should decode punycode: .