Skip to content

Commit 9af4994

Browse files
committed
feat: add validation for baseURL
1 parent b728948 commit 9af4994

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

‎system/HTTP/SiteURI.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace CodeIgniter\HTTP;
1313

1414
use BadMethodCallException;
15+
use CodeIgniter\Exceptions\ConfigException;
1516
use CodeIgniter\HTTP\Exceptions\HTTPException;
1617
use Config\App;
1718

@@ -75,6 +76,13 @@ public function __construct(App $configApp)
7576
// baseURL, so let's help them out.
7677
$baseURL = rtrim($configApp->baseURL, '/ ') . '/';
7778

79+
// Validate baseURL
80+
if (filter_var($baseURL, FILTER_VALIDATE_URL) === false) {
81+
throw new ConfigException(
82+
'Config\App::$baseURL is invalid.'
83+
);
84+
}
85+
7886
$this->baseURL = $baseURL;
7987
$this->indexPage = $configApp->indexPage;
8088

‎tests/system/HTTP/SiteURITest.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace CodeIgniter\HTTP;
1313

1414
use BadMethodCallException;
15+
use CodeIgniter\Exceptions\ConfigException;
1516
use CodeIgniter\HTTP\Exceptions\HTTPException;
1617
use CodeIgniter\Test\CIUnitTestCase;
1718
use Config\App;
@@ -68,6 +69,16 @@ public function testConstructorIndexPageEmpty()
6869
$this->assertSame('http://example.com/', (string) $uri);
6970
}
7071

72+
public function testConstructorInvalidBaseURL()
73+
{
74+
$this->expectException(ConfigException::class);
75+
76+
$config = new App();
77+
$config->baseURL = 'invalid';
78+
79+
new SiteURI($config);
80+
}
81+
7182
public function testSetPath()
7283
{
7384
$config = new App();

0 commit comments

Comments
 (0)