Merge branch '3.6' into 3

This commit is contained in:
Daniel Hensby 2017-07-14 14:53:06 +01:00
commit 36666eb348
No known key found for this signature in database
GPG Key ID: 5DE415D786BBB2FD
3 changed files with 45 additions and 20 deletions

View File

@ -889,24 +889,21 @@ class File extends DataObject {
* @return int * @return int
*/ */
public static function ini2bytes($iniValue) { public static function ini2bytes($iniValue) {
$iniValues = str_split(trim($iniValue)); // Remove non-unit characters from the size
$unit = strtolower(array_pop($iniValues)); $unit = preg_replace('/[^bkmgtpezy]/i', '', $iniValue);
$quantity = (int) implode($iniValues); // Remove non-numeric characters from the size
switch ($unit) { $size = preg_replace('/[^0-9\.]/', '', $iniValue);
case 'g':
$quantity *= 1024; if ($unit) {
// deliberate no break // Find the position of the unit in the ordered string which is the power
case 'm': // of magnitude to multiply a kilobyte by
$quantity *= 1024; $size = round($size * pow(1024, stripos('bkmgtpezy', $unit[0])));
// deliberate no break } else {
case 'k': $size = round($size);
$quantity *= 1024;
// deliberate no break
default:
// no-op: pre-existing behaviour
break;
} }
return $quantity;
// Cast to int - round() returns a float
return (int)$size;
} }
/** /**

View File

@ -868,14 +868,15 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE;
// // Element contains a link // // Element contains a link
// var firstLinkEl = selectedEl.find('a:first'); // var firstLinkEl = selectedEl.find('a:first');
// if(firstLinkEl.length) linkDataSource = firstLinkEl; // if(firstLinkEl.length) linkDataSource = firstLinkEl;
// if(linkDataSource && linkDataSource.length) this.modifySelection(function(ed){
// ed.selectNode(linkDataSource[0]);
// });
} else { } else {
// Element is a child of a link // Element is a child of a link
linkDataSource = selectedEl = selectedEl.parents('a:first'); linkDataSource = selectedEl = selectedEl.parents('a:first');
} }
} }
if(linkDataSource && linkDataSource.length) this.modifySelection(function(ed){
ed.selectNode(linkDataSource[0]);
});
// Is anchor not a link // Is anchor not a link
if (!linkDataSource.attr('href')) linkDataSource = null; if (!linkDataSource.attr('href')) linkDataSource = null;

View File

@ -413,6 +413,33 @@ class FileTest extends SapphireTest {
$this->assertTrue($file->canEdit(), "Admins can edit files"); $this->assertTrue($file->canEdit(), "Admins can edit files");
} }
/**
* Test that ini2bytes returns the number of bytes for a PHP ini style size declaration
*
* @param string $iniValue
* @param int $expected
* @dataProvider ini2BytesProvider
*/
public function testIni2Bytes($iniValue, $expected) {
$this->assertSame($expected, File::ini2bytes($iniValue));
}
/**
* @return array
*/
public function ini2BytesProvider() {
return array(
array('2048', 2 * 1024),
array('2k', 2 * 1024),
array('512M', 512 * 1024 * 1024),
array('512MiB', 512 * 1024 * 1024),
array('512 mbytes', 512 * 1024 * 1024),
array('512 megabytes', 512 * 1024 * 1024),
array('1024g', 1024 * 1024 * 1024 * 1024),
array('1024G', 1024 * 1024 * 1024 * 1024)
);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
public function setUp() { public function setUp() {