Fixed Uri::parseUrl($url) with no path (part 2)

This commit is contained in:
Matias Griese
2018-08-07 23:12:38 +03:00
parent 816a3ebd93
commit 16d2f607c8
2 changed files with 25 additions and 4 deletions

View File

@@ -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'] = '';
}

View File

@@ -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);
}