Skip to content

Commit

Permalink
FIX Cast absoluteUrl() argument to string
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 13, 2022
1 parent 55f8fce commit 2e59d0f
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Control/Director.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public function handleRequest(HTTPRequest $request)
$handler = function () use ($arguments) {
// Redirection
$response = new HTTPResponse();
$response->redirect(static::absoluteURL($arguments['Redirect']));
$response->redirect(static::absoluteUrl((string) $arguments['Redirect']));
return $response;
};
break;
Expand Down
6 changes: 3 additions & 3 deletions src/Control/HTTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static function absoluteURLs($html)
if (preg_match('/^\w+:/', $url ?? '')) {
return $url;
}
return Director::absoluteURL($url);
return Director::absoluteURL((string) $url);
});
}

Expand All @@ -87,8 +87,8 @@ public static function absoluteURLs($html)
* 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>
*
Expand Down
2 changes: 1 addition & 1 deletion src/Control/HTTPResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ protected function htmlRedirect()
{
$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)
Expand Down
2 changes: 1 addition & 1 deletion src/Control/RSS/RSSFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function Title()
*/
public function Link($action = null)
{
return Controller::join_links(Director::absoluteURL($this->link), $action);
return Controller::join_links(Director::absoluteURL((string) $this->link), $action);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Control/RSS/RSSFeed_Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function AbsoluteLink()
return $this->failover->AbsoluteLink();
} else {
if ($this->failover->hasMethod('Link')) {
return Director::absoluteURL($this->failover->Link());
return Director::absoluteURL((string) $this->failover->Link());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Control/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ public function redirectBack(): HTTPResponse
?: Director::baseURL();

// Only direct to absolute urls
$url = Director::absoluteURL($url);
$url = Director::absoluteURL((string) $url);
return $this->redirect($url);
}
}
2 changes: 1 addition & 1 deletion src/Forms/HTMLEditor/TinyMCEConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ protected function getConfig()
);
} elseif (!Director::is_absolute_url($path)) {
// Non-absolute urls are made absolute
$path = Director::absoluteURL($path);
$path = Director::absoluteURL((string) $path);
}
$plugins[$plugin] = $path;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/DatabaseAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected function getReturnURL()
}

// Convert to absolute URL
return Director::absoluteURL($url, true);
return Director::absoluteURL((string) $url, true);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Security/PasswordExpirationMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected function handleExpiredPassword(HTTPRequest $request): ?HTTPResponse
$defaultRedirectUrl = static::config()->get('default_redirect');

if ($sessionRedirectUrl || $defaultRedirectUrl) {
$redirectUrl = $this->absoluteUrl($sessionRedirectUrl ?? $defaultRedirectUrl);
$redirectUrl = $this->absoluteUrl((string) $sessionRedirectUrl ?? $defaultRedirectUrl);
} else {
$redirectUrl = null;
}
Expand All @@ -153,7 +153,7 @@ protected function handleExpiredPassword(HTTPRequest $request): ?HTTPResponse
$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;
Expand All @@ -178,7 +178,7 @@ protected static function absoluteUrl($url): string
// 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) === '/') {
Expand Down
5 changes: 2 additions & 3 deletions tests/php/Security/SecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ public function testExpiredPassword()
$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'),
Expand Down Expand Up @@ -517,9 +517,8 @@ public function testChangePasswordFromLostPassword()
$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');
Expand Down

0 comments on commit 2e59d0f

Please sign in to comment.