From f9a6d22c30938cb73ad2d79c22ce49f37b0fb966 Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Wed, 4 Sep 2024 14:36:24 +0200 Subject: Allow data urls and do not encode as it can break them --- it_html.class | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/it_html.class b/it_html.class index ec1e1ce..e9c1c67 100644 --- a/it_html.class +++ b/it_html.class @@ -506,7 +506,7 @@ static function U(...$args) if (it::match('javascript', $u['scheme'])) $u['scheme'] = ''; - $schemepart = $hostpart ? ($u['scheme'] ? $u['scheme'] . ":" : "") . "//$hostpart" : ($u['scheme'] == "mailto" ? $u['scheme'] . ":" : ""); + $schemepart = $hostpart ? ($u['scheme'] ? $u['scheme'] . ":" : "") . "//$hostpart" : ($u['scheme'] == "data" || $u['scheme'] == "mailto" ? $u['scheme'] . ":" : ""); # remove strings that will be interpreted as scheme from path if (!$schemepart && !$hostpart) @@ -515,7 +515,7 @@ static function U(...$args) # sanitize path and fragment $u['path'] = preg_replace('|\\\\|', '/', $u['path']); # turn \ to / foreach (['path', 'query', 'fragment'] as $key) - $u[$key] = preg_replace_callback('/[^-a-z0-9_.+!*(),:?@&=\/~$%#]|%(?![0-9a-f]{2})/i', function($m) { return rawurlencode($m[0]); }, $u[$key]); + $u[$key] = preg_replace_callback('/[^-a-z0-9_.+!*(),:?@&=\/~$%#]|%(?![0-9a-f]{2})/i', fn($m) => $u['scheme'] != 'data' ? rawurlencode($m[0]) : $m[0], $u[$key]); # convert empty http url path to / if (!$u['path'] && $hostpart && preg_match('/^(https?)?$/', $u['scheme'])) -- cgit v1.2.3