diff options
author | Frederic Guillot <fred@kanboard.net> | 2017-02-04 18:25:41 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2017-02-04 18:25:41 -0500 |
commit | 630707050755f414ce91faf880fd407a6fe63174 (patch) | |
tree | 03318b8ce79c2229e42302b86d2044b01bc09fb2 | |
parent | fe3ac50aca23ed015b7fb523947b468361afa5c8 (diff) |
Do not try to format size if 0
-rw-r--r-- | app/Helper/TextHelper.php | 4 | ||||
-rw-r--r-- | tests/units/Helper/TextHelperTest.php | 1 |
2 files changed, 5 insertions, 0 deletions
diff --git a/app/Helper/TextHelper.php b/app/Helper/TextHelper.php index 654eb171..66583cd1 100644 --- a/app/Helper/TextHelper.php +++ b/app/Helper/TextHelper.php @@ -59,6 +59,10 @@ class TextHelper extends Base */ public function bytes($size, $precision = 2) { + if ($size == 0) { + return 0; + } + $base = log($size) / log(1024); $suffixes = array('', 'k', 'M', 'G', 'T'); diff --git a/tests/units/Helper/TextHelperTest.php b/tests/units/Helper/TextHelperTest.php index 5c8a10f6..35ed5a1e 100644 --- a/tests/units/Helper/TextHelperTest.php +++ b/tests/units/Helper/TextHelperTest.php @@ -107,6 +107,7 @@ class TextHelperTest extends Base { $textHelper = new TextHelper($this->container); + $this->assertEquals('0', $textHelper->bytes(0)); $this->assertEquals('1k', $textHelper->bytes(1024)); $this->assertEquals('33.71k', $textHelper->bytes(34520)); } |