From 6eb11b9717186ea6c0806aff8601a0eff998af10 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 10 Apr 2019 16:50:30 -0600 Subject: [PATCH] Fix for Utils::url and extra base_url --- CHANGELOG.md | 1 + system/src/Grav/Common/Utils.php | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be5646926..dbb026931 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ * Grav 1.6: Fixed Flex erroring out with all numeric keys in storage * Grav 1.6: Fixed error in `FlexUserIndex` if there are users without an email address * Grav 1.6: Fixed bad key in Flex Users if file storage is being used + * Fixed issue with `Utils::url()` method would append extra `base_url` if URL already included it # v1.6.0-rc.4 ## 03/20/2019 diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index b18404b5a..2b1efb42b 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -43,6 +43,12 @@ abstract class Utils return $input; } + /** @var Uri $uri */ + $uri = Grav::instance()['uri']; + + $root = $uri->rootUrl(); + $input = Utils::replaceFirstOccurrence($root, '', $input); + $input = ltrim((string)$input, '/'); if (Utils::contains((string)$input, '://')) { @@ -67,8 +73,7 @@ abstract class Utils $resource = $input; } - /** @var Uri $uri */ - $uri = Grav::instance()['uri']; + return $resource ? rtrim($uri->rootUrl($domain), '/') . '/' . $resource : null; }