Skip to content

Commit

Permalink
fix whitespace encoding in urls (#3719)
Browse files Browse the repository at this point in the history
* fix broken src url encoding

* remove redundant code

* Revert "remove redundant code"

This reverts commit 4e00201.

* Revert "fix broken src url encoding"

This reverts commit 3e8259d.

* encode whitespaces in url paths
  • Loading branch information
dirkjf authored Oct 24, 2023
1 parent b1117e4 commit 6a9b1f2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions system/src/Grav/Common/Page/Markdown/Excerpts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion system/src/Grav/Common/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] : '';

Expand Down

0 comments on commit 6a9b1f2

Please sign in to comment.