Skip to content

Commit

Permalink
Improved Utils::url() to support query strings
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Aug 6, 2018
1 parent 34fa50f commit 18d405d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
1. [](#new)
* Added `Uri::method()` to get current HTTP method (GET/POST etc)
* `FormatterInterface`: Added `getSupportedFileExtensions()` and `getDefaultFileExtension()` methods

1. [](#improved)
* Improved `Utils::url()` to support query strings

# v1.5.0-rc.1
## 07/31/2018

Expand Down
11 changes: 9 additions & 2 deletions system/src/Grav/Common/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ public static function url($input, $domain = false)
/** @var UniformResourceLocator $locator */
$locator = Grav::instance()['locator'];

// Get relative path to the resource (or false if not found).
$resource = $locator->findResource($input, false);
$parts = Uri::parseUrl($input);

$resource = $locator->findResource("{$parts['scheme']}://{$parts['host']}{$parts['path']}", false);

if (isset($parts['query'])) {
$resource = $resource . '?' . $parts['query'];
}


} else {
$resource = $input;
}
Expand Down

0 comments on commit 18d405d

Please sign in to comment.