Merge pull request #10610 from creative-commoners/pulls/5/absolute-link

FIX Cast absoluteUrl() argument to string
This commit is contained in:
Guy Sartorelli 2022-12-14 15:14:25 +13:00 committed by GitHub
commit aefa37f6ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 15 additions and 16 deletions

View File

@ -345,7 +345,7 @@ class Director implements TemplateGlobalProvider
$handler = function () use ($arguments) {
// Redirection
$response = new HTTPResponse();
$response->redirect(static::absoluteURL($arguments['Redirect']));
$response->redirect(static::absoluteUrl((string) $arguments['Redirect']));
return $response;
};
break;

View File

@ -70,7 +70,7 @@ class HTTP
if (preg_match('/^\w+:/', $url ?? '')) {
return $url;
}
return Director::absoluteURL($url);
return Director::absoluteURL((string) $url);
});
}
@ -87,8 +87,8 @@ class HTTP
* As of 3.2 $code should be a callable which takes a single parameter and returns the rewritten,
* for example:
* <code>
* function($url) {
* return Director::absoluteURL($url, true);
* function(string $url) {
* return Director::absoluteURL((string) $url, true);
* }
* </code>
*

View File

@ -346,7 +346,7 @@ class HTTPResponse
{
$headersSent = headers_sent($file, $line);
$location = $this->getHeader('location');
$url = Director::absoluteURL($location);
$url = Director::absoluteURL((string) $location);
$urlATT = Convert::raw2htmlatt($url);
$urlJS = Convert::raw2js($url);
$title = (Director::isDev() && $headersSent)

View File

@ -199,7 +199,7 @@ class RSSFeed extends ViewableData
*/
public function Link($action = null)
{
return Controller::join_links(Director::absoluteURL($this->link), $action);
return Controller::join_links(Director::absoluteURL((string) $this->link), $action);
}
/**

View File

@ -125,7 +125,7 @@ class RSSFeed_Entry extends ViewableData
return $this->failover->AbsoluteLink();
} else {
if ($this->failover->hasMethod('Link')) {
return Director::absoluteURL($this->failover->Link());
return Director::absoluteURL((string) $this->failover->Link());
}
}

View File

@ -658,7 +658,7 @@ class RequestHandler extends ViewableData
?: Director::baseURL();
// Only direct to absolute urls
$url = Director::absoluteURL($url);
$url = Director::absoluteURL((string) $url);
return $this->redirect($url);
}
}

View File

@ -675,7 +675,7 @@ class TinyMCEConfig extends HTMLEditorConfig implements i18nEntityProvider
);
} elseif (!Director::is_absolute_url($path)) {
// Non-absolute urls are made absolute
$path = Director::absoluteURL($path);
$path = Director::absoluteURL((string) $path);
}
$plugins[$plugin] = $path;
}

View File

@ -167,7 +167,7 @@ class DatabaseAdmin extends Controller
}
// Convert to absolute URL
return Director::absoluteURL($url, true);
return Director::absoluteURL((string) $url, true);
}
/**

View File

@ -135,7 +135,7 @@ class PasswordExpirationMiddleware implements HTTPMiddleware
$defaultRedirectUrl = static::config()->get('default_redirect');
if ($sessionRedirectUrl || $defaultRedirectUrl) {
$redirectUrl = $this->absoluteUrl($sessionRedirectUrl ?? $defaultRedirectUrl);
$redirectUrl = $this->absoluteUrl((string) ($sessionRedirectUrl ?? $defaultRedirectUrl));
} else {
$redirectUrl = null;
}
@ -153,7 +153,7 @@ class PasswordExpirationMiddleware implements HTTPMiddleware
$allowedStartswith = static::config()->get('whitelisted_url_startswith');
if (is_array($allowedStartswith)) {
foreach ($allowedStartswith as $pattern) {
$startswith = $this->absoluteUrl($pattern);
$startswith = $this->absoluteUrl((string) $pattern);
if (strncmp($currentUrl ?? '', $startswith ?? '', strlen($startswith ?? '')) === 0) {
return null;
@ -178,7 +178,7 @@ class PasswordExpirationMiddleware implements HTTPMiddleware
// add BASE_URL explicitly if not absolute
$url = Controller::join_links(Director::absoluteBaseURL(), $url);
} else {
$url = Director::absoluteURL($url) ?: Controller::join_links(Director::absoluteBaseURL(), $url);
$url = Director::absoluteURL((string) $url) ?: Controller::join_links(Director::absoluteBaseURL(), $url);
}
if (substr($url ?? '', -1) === '/') {

View File

@ -447,7 +447,7 @@ class SecurityTest extends FunctionalTest
$this->assertEquals(302, $expiredResponse->getStatusCode());
$this->assertEquals(
Director::absoluteURL('Security/changepassword') . '?BackURL=test%2Flink',
Director::absoluteURL($expiredResponse->getHeader('Location'))
Director::absoluteURL((string) $expiredResponse->getHeader('Location'))
);
$this->assertEquals(
$this->idFromFixture(Member::class, 'expiredpassword'),
@ -517,9 +517,8 @@ class SecurityTest extends FunctionalTest
$this->assertEquals(302, $response->getStatusCode());
$this->assertEquals(
Director::absoluteURL('Security/changepassword'),
Director::absoluteURL($response->getHeader('Location'))
Director::absoluteURL((string) $response->getHeader('Location'))
);
// Follow redirection to form without hash in GET parameter
$this->get('Security/changepassword');
$this->doTestChangepasswordForm('1nitialPassword', 'changedPassword#123');