From 6a9b1f221488929db44e7ed3ead16201f1ee38d3 Mon Sep 17 00:00:00 2001 From: dirkjf Date: Tue, 24 Oct 2023 11:30:00 +0200 Subject: [PATCH] fix whitespace encoding in urls (#3719) * fix broken src url encoding * remove redundant code * Revert "remove redundant code" This reverts commit 4e0020114edef4a3061724660d0b8c56d3308533. * Revert "fix broken src url encoding" This reverts commit 3e8259da3ae2ac1f87cd2c1676e97d3ea90754a3. * encode whitespaces in url paths --- system/src/Grav/Common/Page/Markdown/Excerpts.php | 1 + system/src/Grav/Common/Uri.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Markdown/Excerpts.php b/system/src/Grav/Common/Page/Markdown/Excerpts.php index ab3a905d8d..3e192d300c 100644 --- a/system/src/Grav/Common/Page/Markdown/Excerpts.php +++ b/system/src/Grav/Common/Page/Markdown/Excerpts.php @@ -244,6 +244,7 @@ public function processImageExcerpt(array $excerpt): array $id = $element_excerpt['id'] ?? ''; $excerpt['element'] = $medium->parsedownElement($title, $alt, $class, $id, true); + $excerpt['element']['attributes']['src'] = str_replace(' ', '%20', $excerpt['element']['attributes']['src']); } else { // Not a current page media file, see if it needs converting to relative. $excerpt['element']['attributes']['src'] = Uri::buildUrl($url_parts); diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 8eefd50ab1..136c3110bf 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -761,7 +761,7 @@ public static function buildUrl($parsed_url) $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : ''; $pass = ($user || $pass) ? "{$pass}@" : ''; $path = $parsed_url['path'] ?? ''; - $path = !empty($parsed_url['params']) ? rtrim($path, '/') . static::buildParams($parsed_url['params']) : $path; + $path = !empty($parsed_url['params']) ? str_replace(' ', '%20', rtrim($path, '/')) . static::buildParams($parsed_url['params']) : str_replace(' ', '%20', $path); $query = !empty($parsed_url['query']) ? '?' . $parsed_url['query'] : ''; $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';