Skip to content

Commit

Permalink
Format URI directly, fixes codeigniter4#4707
Browse files Browse the repository at this point in the history
  • Loading branch information
MGatner committed May 21, 2021
1 parent 7eef1f7 commit bac8391
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ protected function prepareURL(string $url): string

$uri = $this->baseURI->resolveRelativeURI($url);

return (string) $uri;
// Create the string instead of casting to prevent baseURL muddling
return URI::createURIString($uri->getScheme(), $uri->getAuthority(), $uri->getPath(), $uri->getQuery(), $uri->getFragment());
}

//--------------------------------------------------------------------
Expand Down
18 changes: 18 additions & 0 deletions tests/system/HTTP/CURLRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ protected function getRequest(array $options = [])

//--------------------------------------------------------------------

/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/4707
*/
public function testPrepareURLIgnoresAppConfig()
{
config('App')->baseURL = 'http://example.com/fruit/';

$request = $this->getRequest([
'base_uri' => 'http://example.com/v1/',
]);

$method = $this->getPrivateMethodInvoker($request, 'prepareURL');

$this->assertEquals('http://example.com/v1/bananas', $method('bananas'));
}

//--------------------------------------------------------------------

/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/1029
*/
Expand Down

0 comments on commit bac8391

Please sign in to comment.