Skip to content

Commit

Permalink
Issue #3156879 by alexpott, Krzysztof Domański: \Drupal\Component\Uti…
Browse files Browse the repository at this point in the history
…lity\Bytes::toInt() - ensure $size is a number type

(cherry picked from commit ff722653958673b16619c98ec0e5fd2fcd91e6af)
  • Loading branch information
larowlan committed Aug 3, 2020
1 parent a30e371 commit 035faa2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/Drupal/Component/Utility/Bytes.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public static function toInt($size) {
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);
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/Drupal/Tests/Component/Utility/BytesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public function providerTestToInt() {
['76MRandomStringThatShouldBeIgnoredByParseSize.', 79691776],
// 76.24 GB (with typo).
['76.24 Giggabyte', 81862076662],
['1.5', 2],
['2.4', 2],
['', 0],
];
}

Expand Down

0 comments on commit 035faa2

Please sign in to comment.