Permalink
Browse files

merged branch jfsimon/issue-7481 (PR #7489)

This PR was merged into the master branch.

Discussion
----------

Fixes bytes convertion method, last episode

This definitely fixes the bytes convertion method.

@lazyhammer thanks for your support & indulgence
@fabpot sorry for the running gag
@vicb I opened a ticket: https://bugs.php.net/bug.php?id=64530

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #7481

Commits
-------

233b945 fixed bytes convertion method, again
  • Loading branch information...
2 parents bbb516f + 233b945 commit ea79360fba475ef30222ff5d1750ff6f30934414 @fabpot fabpot committed Mar 27, 2013
@@ -29,11 +29,11 @@ public function getPostMaxSize()
return null;
}
- if (preg_match('#^\+?(0X?)?([^KMG]*)([KMG]?)#', $iniMax, $match)) {
+ if (preg_match('#^\+?(0X?)?(.*?)([KMG]?)$#', $iniMax, $match)) {
$shifts = array('' => 0, 'K' => 10, 'M' => 20, 'G' => 30);
$bases = array('' => 10, '0' => 8, '0X' => 16);
- return (intval($match[2], $bases[$match[1]]) * (1 << $shifts[$match[3]]));
+ return intval($match[2], $bases[$match[1]]) << $shifts[$match[3]];
}
return 0;
@@ -30,13 +30,17 @@ public function getGetPostMaxSizeTestData()
return array(
array('2k', 2048),
array('2 k', 2048),
+ array('8m', 8 * 1024 * 1024),
array('+2 k', 2048),
array('+2???k', 2048),
array('0x10', 16),
array('0xf', 15),
array('010', 8),
array('+0x10 k', 16 * 1024),
array('1g', 1024 * 1024 * 1024),
+ array('-1', -1),
+ array('0', 0),
+ array('2mk', 2048), // the unit must be the last char, so in this case 'k', not 'm'
);
}
}
@@ -237,11 +237,11 @@ public static function getMaxFilesize()
return PHP_INT_MAX;
}
- if (preg_match('#^\+?(0x?)?([^kmg]*)([kmg]?)#', $max, $match)) {
+ if (preg_match('#^\+?(0x?)?(.*?)([kmg]?)$#', $max, $match)) {
$shifts = array('' => 0, 'k' => 10, 'm' => 20, 'g' => 30);
$bases = array('' => 10, '0' => 8, '0x' => 16);
- return (intval($match[2], $bases[$match[1]]) * (1 << $shifts[$match[3]]));
+ return intval($match[2], $bases[$match[1]]) << $shifts[$match[3]];
}
return 0;
@@ -79,11 +79,11 @@ private function convertToBytes($memoryLimit)
return -1;
}
- if (preg_match('#^\+?(0x?)?([^kmg]*)([kmg]?)#', $memoryLimit, $match)) {
+ if (preg_match('#^\+?(0x?)?(.*?)([kmg]?)$#', $memoryLimit, $match)) {
$shifts = array('' => 0, 'k' => 10, 'm' => 20, 'g' => 30);
$bases = array('' => 10, '0' => 8, '0x' => 16);
- return (intval($match[2], $bases[$match[1]]) * (1 << $shifts[$match[3]]));
+ return intval($match[2], $bases[$match[1]]) << $shifts[$match[3]];
}
return 0;
@@ -48,13 +48,17 @@ public function getBytesConversionTestData()
return array(
array('2k', 2048),
array('2 k', 2048),
+ array('8m', 8 * 1024 * 1024),
array('+2 k', 2048),
array('+2???k', 2048),
array('0x10', 16),
array('0xf', 15),
array('010', 8),
array('+0x10 k', 16 * 1024),
array('1g', 1024 * 1024 * 1024),
+ array('-1', -1),
+ array('0', 0),
+ array('2mk', 2048), // the unit must be the last char, so in this case 'k', not 'm'
);
}
}

0 comments on commit ea79360

Please sign in to comment.