From 16d2f607c8981249c1039c9710692bbc3322104f Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 7 Aug 2018 23:12:38 +0300 Subject: [PATCH] Fixed Uri::parseUrl($url) with no path (part 2) --- system/src/Grav/Common/Uri.php | 18 +++++++++++++++++- system/src/Grav/Common/Utils.php | 11 ++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 67eb8471e..4bb6bc7b1 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -880,7 +880,23 @@ class Uri public static function parseUrl($url) { $grav = Grav::instance(); - $parts = parse_url($url); + + $encodedUrl = preg_replace_callback( + '%[^:/@?&=#]+%usD', + function ($matches) { return rawurlencode($matches[0]); }, + $url + ); + + $parts = parse_url($encodedUrl); + + if (false === $parts) { + return false; + } + + foreach($parts as $name => $value) { + $parts[$name] = rawurldecode($value); + } + if (!isset($parts['path'])) { $parts['path'] = ''; } diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index 8ed1a30c1..1cf7ac751 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -47,10 +47,15 @@ abstract class Utils $parts = Uri::parseUrl($input); - $resource = $locator->findResource("{$parts['scheme']}://{$parts['host']}{$parts['path']}", false); + if ($parts) { + $resource = $locator->findResource("{$parts['scheme']}://{$parts['host']}{$parts['path']}", false); - if (isset($parts['query'])) { - $resource = $resource . '?' . $parts['query']; + if (isset($parts['query'])) { + $resource = $resource . '?' . $parts['query']; + } + } else { + // Not a valid URL (can still be a stream). + $resource = $locator->findResource($input, false); }