Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion system/HTTP/URI.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,10 @@ public function __toString(): string
$baseUri = new self($config->baseURL);

// If the hosts matches then assume this should be relative to baseURL
if ($this->getHost() === $baseUri->getHost()) {
if (
substr($this->getScheme(), 0, 4) === 'http'
&& $this->getHost() === $baseUri->getHost()
) {
// Check for additional segments
$basePath = trim($baseUri->getPath(), '/') . '/';
$trimPath = ltrim($path, '/');
Expand Down
16 changes: 16 additions & 0 deletions tests/system/HTTP/URITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -985,4 +985,20 @@ public function testCreateURIString()

$this->assertSame($expected, $uri);
}

/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/5728
*/
public function testForceGlobalSecureRequestsAndNonHTTPProtocol()
{
$config = new App();
$config->forceGlobalSecureRequests = true;
$config->baseURL = 'https://localhost/';
Factories::injectMock('config', 'App', $config);

$expected = 'ftp://localhost/path/to/test.txt';
$uri = new URI($expected);

$this->assertSame($expected, (string) $uri);
}
}