Skip to content

Commit

Permalink
Fixed Uri::parseUrl($url) with no path (part 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Aug 7, 2018
1 parent 816a3eb commit 16d2f60
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
18 changes: 17 additions & 1 deletion system/src/Grav/Common/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,23 @@ public static function convertUrl(Page $page, $url, $type = 'link', $absolute =
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'] = '';
}
Expand Down
11 changes: 8 additions & 3 deletions system/src/Grav/Common/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ public static function url($input, $domain = false)

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


Expand Down

0 comments on commit 16d2f60

Please sign in to comment.