From ff722653958673b16619c98ec0e5fd2fcd91e6af Mon Sep 17 00:00:00 2001 From: Lee Rowlands Date: Fri, 31 Jul 2020 11:47:00 +1000 Subject: [PATCH] =?UTF-8?q?Issue=20#3156879=20by=20alexpott,=20Krzysztof?= =?UTF-8?q?=20Doma=C5=84ski:=20\Drupal\Component\Utility\Bytes::toInt()=20?= =?UTF-8?q?-=20ensure=20$size=20is=20a=20number=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Drupal/Component/Utility/Bytes.php | 3 ++- core/tests/Drupal/Tests/Component/Utility/BytesTest.php | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/lib/Drupal/Component/Utility/Bytes.php b/core/lib/Drupal/Component/Utility/Bytes.php index d625b123641..477e6e48dad 100644 --- a/core/lib/Drupal/Component/Utility/Bytes.php +++ b/core/lib/Drupal/Component/Utility/Bytes.php @@ -35,7 +35,8 @@ class Bytes { return round($size * pow(self::KILOBYTE, stripos('bkmgtpezy', $unit[0]))); } else { - return round($size); + // Ensure size is a proper number type. + return round((float) $size); } } diff --git a/core/tests/Drupal/Tests/Component/Utility/BytesTest.php b/core/tests/Drupal/Tests/Component/Utility/BytesTest.php index 72485ea8026..0b54a515024 100644 --- a/core/tests/Drupal/Tests/Component/Utility/BytesTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/BytesTest.php @@ -56,6 +56,9 @@ class BytesTest extends TestCase { ['76MRandomStringThatShouldBeIgnoredByParseSize.', 79691776], // 76.24 GB (with typo). ['76.24 Giggabyte', 81862076662], + ['1.5', 2], + ['2.4', 2], + ['', 0], ]; }