From 645c9a122c3236c1ac5fc036cb598b9a91c1c2ee Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Thu, 22 Aug 2024 11:51:24 -0400 Subject: [PATCH] Update `cleanURL` helper function to match later Marked version --- shared/naturalcrit/markdown.js | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 9388e912a..be2f56af9 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -86,7 +86,7 @@ renderer.link = function (href, title, text) { if(href[0] == '#') { self = true; } - href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); + href = cleanUrl(href); if(href === null) { return text; @@ -712,28 +712,14 @@ Marked.use(mustacheInjectBlock); Marked.use({ renderer: renderer, tokenizer: tokenizer, mangle: false }); Marked.use(MarkedExtendedTables(), MarkedGFMHeadingId(), MarkedSmartypantsLite(), MarkedEmojis(MarkedEmojiOptions)); -const nonWordAndColonTest = /[^\w:]/g; -const cleanUrl = function (sanitize, base, href) { - if(sanitize) { - let prot; - try { - prot = decodeURIComponent(unescape(href)) - .replace(nonWordAndColonTest, '') - .toLowerCase(); - } catch (e) { - return null; - } - if(prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) { - return null; - } - } - try { - href = encodeURI(href).replace(/%25/g, '%'); - } catch (e) { - return null; - } - return href; -}; +function cleanUrl(href) { + try { + href = encodeURI(href).replace(/%25/g, '%'); + } catch { + return null; + } + return href; +} const escapeTest = /[&<>"']/; const escapeReplace = /[&<>"']/g;