Skip to content

Commit

Permalink
Fixed #15533
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Aug 15, 2024
1 parent ea7e539 commit 9f7bc6d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for Craft CMS 4

## Unreleased

- Fixed a bug where `craft\helpers\App::env()` and `normalizeValue()` could return incorrect results for values that looked like floats. ([#15533](https://github.com/craftcms/cms/issues/15533))

## 4.11.3 - 2024-08-13

- Fixed a bug where the system name in the control panel’s global sidebar was getting hyperlinked even if the primary site didn’t have a URL. ([#15525](https://github.com/craftcms/cms/issues/15525))
Expand Down
26 changes: 20 additions & 6 deletions src/helpers/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,26 @@ public static function extensionVersion(string $name): string
*/
public static function normalizeValue(mixed $value): mixed
{
return match (is_string($value) ? strtolower($value) : $value) {
'true' => true,
'false' => false,
'null' => null,
default => Number::isIntOrFloat($value) ? Number::toIntOrFloat($value) : $value,
};
if (is_string($value)) {
switch (strtolower($value)) {
case 'true':
return true;
case 'false':
return false;
case 'null':
return null;
}

if (Number::isIntOrFloat($value)) {
$intOrFloat = Number::toIntOrFloat($value);
// make sure we didn't lose any precision
if ((string)$intOrFloat === $value) {
return $intOrFloat;
}
}
}

return $value;
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/unit/helpers/AppHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ public function normalizeValueDataProvider(): array
[123.4, '123.4'],
['foo', 'foo'],
[null, null],
['2833563543.1341693581393', '2833563543.1341693581393'], // https://github.com/craftcms/cms/issues/15533
];
}

Expand Down

0 comments on commit 9f7bc6d

Please sign in to comment.