diff --git a/CHANGELOG.md b/CHANGELOG.md index 79c680ef7..5f5ccf218 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Added support to get image size for SVG vector images [#3533](https://github.com/getgrav/grav/pull/3533) * Added XSS check for uploaded SVG files before they get stored * Fixed phpstan issues (All level 2, Framework level 5) + * Added a `system.legacy_url_root_behavior` config option to enable legacy/broken `Utils::url()` behavior 2. [](#bugfix) * Fixed `'mbstring' extension is not loaded` error, use Polyfill instead [#3504](https://github.com/getgrav/grav/pull/3504) * Fixed new `Utils::pathinfo()` and `Utils::basename()` being too strict for legacy use [#3542](https://github.com/getgrav/grav/issues/3542) diff --git a/system/config/system.yaml b/system/config/system.yaml index 2de075b26..9fba968a9 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -15,6 +15,7 @@ http_x_forwarded: # Configuration options for the host: false port: true ip: true +legacy_url_root_behavior: false # Enable legacy root URL behavior that breaks URls with paths that match root languages: supported: [] # List of languages supported. eg: [en, fr, de] diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index 5ae819361..017c49822 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -134,14 +134,15 @@ abstract class Utils $resource = $locator->findResource($input, false); } } else { -// $root = $uri->rootUrl(); -// $pattern = '/(' . '\\' . $root . '[\s\/])/'; -// if (preg_match($pattern, $input, $matches)) { -// $input = static::replaceFirstOccurrence($matches[0], '', $input); -// } + // You can manually restore the old legacy behavior that does not produce expected results + if ($grav['config']->get('system.legacy_url_root_behavior', false)) { + $root = $uri->rootUrl(); + if (static::startsWith($input, $root)) { + $input = static::replaceFirstOccurrence($root, '', $input); + } + } $input = ltrim($input, '/'); - $resource = $input; }