mirror of
https://github.com/getgrav/grav.git
synced 2026-07-20 21:41:13 +02:00
Fixed Uri::parseUrl($url) with no path (part 2)
This commit is contained in:
@@ -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'] = '';
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user