Skip to content

Commit cb0e9ac

Browse files
authored
Handle null value the same as unset (#1740)
* Handle null value the same as unset * Fix tests * Remove obsolete if-statement
1 parent 2523634 commit cb0e9ac

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/SimpleSAML/Configuration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use function interface_exists;
1919
use function is_array;
2020
use function is_int;
21+
use function is_null;
2122
use function is_string;
2223
use function ob_end_clean;
2324
use function ob_get_length;
@@ -415,7 +416,7 @@ public function getOptionalValue(string $name, $default)
415416
*/
416417
public function hasValue(string $name): bool
417418
{
418-
return array_key_exists($name, $this->configuration);
419+
return array_key_exists($name, $this->configuration) && !is_null($this->configuration[$name]);
419420
}
420421

421422

src/SimpleSAML/SessionHandlerPHP.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function __construct()
5454
);
5555

5656
if (session_status() === PHP_SESSION_ACTIVE) {
57-
if (session_name() === $this->cookie_name || $this->cookie_name === null) {
57+
if (session_name() === $this->cookie_name) {
5858
Logger::warning(
5959
'There is already a PHP session with the same name as SimpleSAMLphp\'s session, or the ' .
6060
"'session.phpsession.cookiename' configuration option is not set. Make sure to set " .

tests/src/SimpleSAML/ConfigurationTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ public function testGetValue(): void
7272

7373
// Normal use
7474
$this->assertTrue($c->getValue('exists_true'));
75-
$this->assertNull($c->getValue('exists_null'));
75+
76+
// Null option
77+
$this->expectException(AssertionFailedException::class);
78+
$c->getValue('exists_null');
7679

7780
// Missing option
7881
$this->expectException(AssertionFailedException::class);
@@ -108,7 +111,7 @@ public function testHasValue(): void
108111
]);
109112
$this->assertEquals($c->hasValue('missing'), false);
110113
$this->assertEquals($c->hasValue('exists_true'), true);
111-
$this->assertEquals($c->hasValue('exists_null'), true);
114+
$this->assertEquals($c->hasValue('exists_null'), false);
112115
}
113116

114117

@@ -124,7 +127,7 @@ public function testHasValueOneOf(): void
124127
$this->assertEquals($c->hasValueOneOf([]), false);
125128
$this->assertEquals($c->hasValueOneOf(['missing']), false);
126129
$this->assertEquals($c->hasValueOneOf(['exists_true']), true);
127-
$this->assertEquals($c->hasValueOneOf(['exists_null']), true);
130+
$this->assertEquals($c->hasValueOneOf(['exists_null']), false);
128131

129132
$this->assertEquals($c->hasValueOneOf(['missing1', 'missing2']), false);
130133
$this->assertEquals($c->hasValueOneOf(['exists_true', 'missing']), true);

0 commit comments

Comments
 (0)