Skip to content

Commit 6cc31fc

Browse files
committed
fix: forceGlobalSecureRequests break URI schemes other than HTTP
1 parent b343d33 commit 6cc31fc

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

system/HTTP/URI.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ public function __toString(): string
596596
}
597597

598598
// Check for forced HTTPS
599-
if ($config->forceGlobalSecureRequests) {
599+
if ($config->forceGlobalSecureRequests && $this->getScheme() === 'http') {
600600
$scheme = 'https';
601601
}
602602
}

tests/system/HTTP/URITest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,4 +985,20 @@ public function testCreateURIString()
985985

986986
$this->assertSame($expected, $uri);
987987
}
988+
989+
/**
990+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/5728
991+
*/
992+
public function testForceGlobalSecureRequestsAndNonHTTPProtocol()
993+
{
994+
$config = new App();
995+
$config->forceGlobalSecureRequests = true;
996+
$config->baseURL = 'https://localhost/';
997+
Factories::injectMock('config', 'App', $config);
998+
999+
$expected = 'ftp://localhost/path/to/test.txt';
1000+
$uri = new URI($expected);
1001+
1002+
$this->assertSame($expected, (string) $uri);
1003+
}
9881004
}

0 commit comments

Comments
 (0)