Skip to content
This repository
Browse code

allow for lowercase as well, also strip the unit part off before pow()

  • Loading branch information...
commit ff676b5ea4a2c19d2bf3205d72bde81d61a5db97 1 parent 90c32ad
ceeram authored September 18, 2012
1  lib/Cake/Test/Case/Utility/CakeNumberTest.php
@@ -555,6 +555,7 @@ public function filesizes() {
555 555
 			array(array('size' => '1KB', 'default' => false), 1024),
556 556
 			array(array('size' => '1.5KB', 'default' => false), 1536),
557 557
 			array(array('size' => '1MB', 'default' => false), 1048576),
  558
+			array(array('size' => '1mb', 'default' => false), 1048576),
558 559
 			array(array('size' => '1.5MB', 'default' => false), 1572864),
559 560
 			array(array('size' => '1GB', 'default' => false), 1073741824),
560 561
 			array(array('size' => '1.5GB', 'default' => false), 1610612736),
3  lib/Cake/Utility/CakeNumber.php
@@ -112,13 +112,16 @@ public static function fromReadableSize($size, $default = false) {
112 112
 		if (ctype_digit($size)) {
113 113
 			return $size * 1;
114 114
 		}
  115
+		$size = strtoupper($size);
115 116
 
116 117
 		$i = array_search(substr($size, -2), array('KB', 'MB', 'GB', 'TB', 'PB'));
117 118
 		if ($i !== false) {
  119
+			$size = substr($size, 0, strlen($size) -2);
118 120
 			return $size * pow(1024, $i + 1);
119 121
 		}
120 122
 
121 123
 		if (substr($size, -1) == 'B' && ctype_digit(substr($size, 0, strlen($size) - 1))) {
  124
+			$size = substr($size, 0, strlen($size) - 1);
122 125
 			return $size * 1;
123 126
 		}
124 127
 

0 notes on commit ff676b5

Please sign in to comment.
Something went wrong with that request. Please try again.