Skip to content

Commit bac8391

Browse files
committed
Format URI directly, fixes #4707
1 parent 7eef1f7 commit bac8391

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

system/HTTP/CURLRequest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ protected function prepareURL(string $url): string
347347

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

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

353354
//--------------------------------------------------------------------

tests/system/HTTP/CURLRequestTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ protected function getRequest(array $options = [])
3333

3434
//--------------------------------------------------------------------
3535

36+
/**
37+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/4707
38+
*/
39+
public function testPrepareURLIgnoresAppConfig()
40+
{
41+
config('App')->baseURL = 'http://example.com/fruit/';
42+
43+
$request = $this->getRequest([
44+
'base_uri' => 'http://example.com/v1/',
45+
]);
46+
47+
$method = $this->getPrivateMethodInvoker($request, 'prepareURL');
48+
49+
$this->assertEquals('http://example.com/v1/bananas', $method('bananas'));
50+
}
51+
52+
//--------------------------------------------------------------------
53+
3654
/**
3755
* @see https://github.com/codeigniter4/CodeIgniter4/issues/1029
3856
*/

0 commit comments

Comments
 (0)