diff --git a/Parsedown.php b/Parsedown.php index 0bd81e2..702b041 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -87,7 +87,6 @@ class Parsedown protected $safeLinksWhitelist = array( 'http://', 'https://', - '/', 'ftp://', 'ftps://', 'mailto:', @@ -1554,7 +1553,14 @@ class Parsedown if ( ! $safe) { - unset($Element['attributes'][$attribute]); + $Element['attributes'][$attribute] = preg_replace_callback( + '/[^\/#?&=%]++/', + function (array $match) + { + return urlencode($match[0]); + }, + $Element['attributes'][$attribute] + ); } } diff --git a/test/data/inline_link.html b/test/data/inline_link.html index cef29cf..7a3131b 100644 --- a/test/data/inline_link.html +++ b/test/data/inline_link.html @@ -1,5 +1,5 @@

link

-

link with parentheses in URL

+

link with parentheses in URL

(link) in parentheses

link

MD Logo

diff --git a/test/data/xss_bad_url.html b/test/data/xss_bad_url.html index 93dd0d8..8e43877 100644 --- a/test/data/xss_bad_url.html +++ b/test/data/xss_bad_url.html @@ -1,16 +1,16 @@ -

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

\ No newline at end of file +

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

\ No newline at end of file