Skip to content

Commit

Permalink
fix: forceGlobalSecureRequests break URI schemes other than HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Feb 24, 2022
1 parent b343d33 commit 97640c9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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);
}
}

0 comments on commit 97640c9

Please sign in to comment.