diff --git a/CHANGELOG.md b/CHANGELOG.md index 5161707e30f..7ef7a6b61e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/src/helpers/App.php b/src/helpers/App.php index 2073c86ce85..f3a0035fc01 100644 --- a/src/helpers/App.php +++ b/src/helpers/App.php @@ -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; } /** diff --git a/tests/unit/helpers/AppHelperTest.php b/tests/unit/helpers/AppHelperTest.php index 3ff5238fd64..2ad35323915 100644 --- a/tests/unit/helpers/AppHelperTest.php +++ b/tests/unit/helpers/AppHelperTest.php @@ -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 ]; }