Skip to content

Commit af57be5

Browse files
committed
[setup] 0 == null, but 0 !== null...
1 parent c8a11a2 commit af57be5

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

core/Util/PolyfillsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public function test_parse_shorthand_int(): void
8181
{
8282
self::assertEquals(null, parse_shorthand_int("foo"));
8383
self::assertEquals(-1, parse_shorthand_int("-1"));
84+
self::assertEquals(0, parse_shorthand_int("0"));
8485
self::assertEquals(33554432, parse_shorthand_int("32M"));
8586
self::assertEquals(44441, parse_shorthand_int("43.4KB"));
8687
self::assertEquals(1231231231, parse_shorthand_int("1231231231"));

ext/setup/main.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static function postToSettings(QueryArray $post): array
5959
$settings[$key] = $value;
6060
} elseif ($type === "int") {
6161
assert(!is_array($value));
62-
$settings[$key] = $value ? parse_shorthand_int($value) : null;
62+
$settings[$key] = $value !== null ? parse_shorthand_int($value) : null;
6363
} elseif ($type === "bool") {
6464
$settings[$key] = $value === "on";
6565
} elseif ($type === "array") {

ext/setup/test.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ final class SetupTest extends ShimmiePHPUnitTestCase
88
{
99
public function testParseSettings(): void
1010
{
11-
self::assertEquals(
11+
self::assertSame(
1212
[
1313
"mynull" => null,
1414
"mystring" => "hello world!",
@@ -18,8 +18,8 @@ public function testParseSettings(): void
1818
"myarray" => ["hello", "world"],
1919
"emptystring" => null,
2020
"emptyint" => null,
21-
"emptybool" => null,
2221
"emptyarray" => null,
22+
"zero" => 0,
2323
],
2424
ConfigSaveEvent::postToSettings(new QueryArray([
2525
// keys in POST that don't start with _type or _config are ignored
@@ -44,10 +44,11 @@ public function testParseSettings(): void
4444
"_config_emptystring" => "",
4545
"_type_emptyint" => "int",
4646
"_config_emptyint" => "",
47-
"_type_emptybool" => "bool",
48-
"_config_emptybool" => "",
4947
"_type_emptyarray" => "array",
5048
"_config_emptyarray" => "",
49+
// "0" should not be null
50+
"_type_zero" => "int",
51+
"_config_zero" => "0",
5152
]))
5253
);
5354

0 commit comments

Comments
 (0)