FIX: Treat absolute links in a consistent manner in get_by_link.

Fixes #2580 

The call to `Director::makeRelative` transforms absolute links into relative links. Previously, this meant that you could pass in "https://example.co.nz/about-us" or "about-us" and get the same result, but passing in "https://example.co.nz/" and "/"  would give _different_ results.
This commit performs the transformation to a relative link _before_ checking if the path should be for the home page, which leads to more consistent results.
This commit is contained in:
GuySartorelli 2021-09-21 17:09:48 +12:00 committed by GitHub
parent f3a76ccf2d
commit 734eb3921f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 3 deletions

View File

@ -415,9 +415,8 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$urlSegmentExpr = sprintf('"%s"."URLSegment"', $tableName);
$parentIDExpr = sprintf('"%s"."ParentID"', $tableName);
if (trim($link, '/')) {
$link = trim(Director::makeRelative($link), '/');
} else {
$link = trim(Director::makeRelative($link), '/');
if (!$link) {
$link = RootURLController::get_homepage_link();
}