Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Cast absoluteUrl() argument to string #10610

Merged

Conversation

emteknetnz
Copy link
Member

@emteknetnz emteknetnz force-pushed the pulls/5/absolute-link branch from 10c7b02 to 2ffa27d Compare December 8, 2022 21:17
Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See silverstripe/silverstripe-cms#2806 (comment) for a discussion on this approach. Strongly typing the return type of the given methods is out of scope for CMS 5.

Some to remove here where it's not necessary though. It's a fairly small PR so I think it's reasonable to only do this where the variable can actually be something other than a string.

Comment on lines 100 to 102
$this->assertEquals("http://www.mysite.com:9090/mysite/", Director::absoluteURL((string) $url, Director::BASE));
$this->assertEquals("http://www.mysite.com:9090/", Director::absoluteURL((string) $url, Director::ROOT));
$this->assertEquals("http://www.mysite.com:9090/mysite/sub-page/", Director::absoluteURL((string) $url, Director::REQUEST));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->assertEquals("http://www.mysite.com:9090/mysite/", Director::absoluteURL((string) $url, Director::BASE));
$this->assertEquals("http://www.mysite.com:9090/", Director::absoluteURL((string) $url, Director::ROOT));
$this->assertEquals("http://www.mysite.com:9090/mysite/sub-page/", Director::absoluteURL((string) $url, Director::REQUEST));
$this->assertEquals("http://www.mysite.com:9090/mysite/", Director::absoluteURL($url, Director::BASE));
$this->assertEquals("http://www.mysite.com:9090/", Director::absoluteURL($url, Director::ROOT));
$this->assertEquals("http://www.mysite.com:9090/mysite/sub-page/", Director::absoluteURL($url, Director::REQUEST));

Not necessary here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@@ -475,7 +475,7 @@ public function testRedirectBackByBackUrl()
$externalAbsoluteUrl = 'http://myhost.com/some-url';
$response = $this->get('TestController/redirectbacktest?BackURL=' . urlencode($externalAbsoluteUrl ?? ''));
$this->assertEquals(
Director::absoluteURL($link),
Director::absoluteURL((string) $link),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Director::absoluteURL((string) $link),
Director::absoluteURL($link),

Not necessary here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@@ -145,15 +145,15 @@ protected function handleExpiredPassword(HTTPRequest $request): ?HTTPResponse
return null;
}

$currentUrl = $this->absoluteUrl($request->getURL(true));
$currentUrl = $this->absoluteUrl((string) $request->getURL(true));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$currentUrl = $this->absoluteUrl((string) $request->getURL(true));
$currentUrl = $this->absoluteUrl($request->getURL(true));

Not necessary here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be keen to understand how this cast-to-string is affecting that unit test - I would have expected the CI to fail by throwing an exception if the problem was that the wrong type is being passed to a strongly-typed parameter.

@@ -863,7 +863,7 @@ public static function get_tinymce_lang_url(): string
$dir = static::config()->get('lang_dir');
if ($lang !== 'en' && !empty($dir)) {
$resource = ModuleResourceLoader::singleton()->resolveResource($dir);
return Director::absoluteURL($resource->getRelativeResource($lang . '.js')->getURL());
return Director::absoluteURL((string) $resource->getRelativeResource($lang . '.js')->getURL());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return Director::absoluteURL((string) $resource->getRelativeResource($lang . '.js')->getURL());
return Director::absoluteURL($resource->getRelativeResource($lang . '.js')->getURL());

Not necessary here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

src/Forms/HTMLEditor/TinyMCEConfig.php Show resolved Hide resolved
@@ -666,7 +666,7 @@ protected function getConfig()
$plugins = [];
foreach ($this->getPlugins() as $plugin => $path) {
if ($path instanceof ModuleResource) {
$path = Director::absoluteURL($path->getURL());
$path = Director::absoluteURL((string) $path->getURL());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$path = Director::absoluteURL((string) $path->getURL());
$path = Director::absoluteURL($path->getURL());

Not needed here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@@ -581,7 +581,7 @@ public function Link($action = null)
*/
public function redirect(string $url, int $code = 302): HTTPResponse
{
$url = Director::absoluteURL($url);
$url = Director::absoluteURL((string) $url);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$url = Director::absoluteURL((string) $url);
$url = Director::absoluteURL($url);

Not needed here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment on lines 90 to 91
* function($url) {
* return Director::absoluteURL($url, true);
* return Director::absoluteURL((string) $url, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets do function(string $url) here instead to promote good standards

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@@ -52,7 +52,7 @@ public static function filename2url($filename)
}

$relativePath = ltrim(substr($filename ?? '', $baseLength ?? 0), '/\\');
return Director::absoluteURL($relativePath);
return Director::absoluteURL((string) $relativePath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return Director::absoluteURL((string) $relativePath);
return Director::absoluteURL($relativePath);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@emteknetnz emteknetnz force-pushed the pulls/5/absolute-link branch from 2ffa27d to 2e59d0f Compare December 13, 2022 21:57
@emteknetnz emteknetnz force-pushed the pulls/5/absolute-link branch from 2e59d0f to 700288d Compare December 13, 2022 22:24
@GuySartorelli GuySartorelli merged commit aefa37f into silverstripe:5 Dec 14, 2022
@GuySartorelli GuySartorelli deleted the pulls/5/absolute-link branch December 14, 2022 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants