diff --git a/system/Common.php b/system/Common.php index e78f7c6ad7f1..6eeb55a3b784 100644 --- a/system/Common.php +++ b/system/Common.php @@ -1015,11 +1015,13 @@ function slash_item(string $item): ?string { $config = config(App::class); + $configItem = ''; + if (property_exists($config, $item)) { - $configItem = $config->{$item}; + $configItem = (string) $config->{$item}; } - if (! isset($configItem) || empty(trim($configItem))) { + if (trim($configItem) === '') { return null; } diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index 3dd8cfe3cfe8..cdf9a8af7a9d 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -390,9 +390,9 @@ public function testReallyWritable() public function testSlashItem() { - $this->assertSame('/', slash_item('cookiePath')); // slash already there - $this->assertNull(null, slash_item('cookieDomain')); // empty, so untouched - $this->assertSame('en/', slash_item('defaultLocale')); // slash appended + $this->assertSame('/', slash_item('cookiePath')); + $this->assertNull(slash_item('cookieDomain')); + $this->assertSame('en/', slash_item('defaultLocale')); } protected function injectSessionMock()