From b2d362beb90193f043c322cdb5554b152bb1a920 Mon Sep 17 00:00:00 2001 From: Mojmir Fendek Date: Thu, 22 Jun 2017 10:07:48 +1200 Subject: [PATCH 1/2] Html editor selection is now properly stored while the dialog is open. --- javascript/HtmlEditorField.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/javascript/HtmlEditorField.js b/javascript/HtmlEditorField.js index f8e709d19..b2034b71b 100644 --- a/javascript/HtmlEditorField.js +++ b/javascript/HtmlEditorField.js @@ -868,14 +868,15 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE; // // Element contains a link // var firstLinkEl = selectedEl.find('a:first'); // if(firstLinkEl.length) linkDataSource = firstLinkEl; + + // if(linkDataSource && linkDataSource.length) this.modifySelection(function(ed){ + // ed.selectNode(linkDataSource[0]); + // }); } else { // Element is a child of a link linkDataSource = selectedEl = selectedEl.parents('a:first'); } } - if(linkDataSource && linkDataSource.length) this.modifySelection(function(ed){ - ed.selectNode(linkDataSource[0]); - }); // Is anchor not a link if (!linkDataSource.attr('href')) linkDataSource = null; From 960a0f8343e5ff8379906c2476af4b74da0fd9c9 Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Mon, 10 Jul 2017 09:41:36 +0100 Subject: [PATCH 2/2] Fix: Make File::ini2bytes() compliant with binary prefixes (fixes #7145) --- filesystem/File.php | 31 ++++++++++++++----------------- tests/filesystem/FileTest.php | 27 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/filesystem/File.php b/filesystem/File.php index 5750414ac..fb07ac5c7 100644 --- a/filesystem/File.php +++ b/filesystem/File.php @@ -887,24 +887,21 @@ class File extends DataObject { * @return int */ public static function ini2bytes($iniValue) { - $iniValues = str_split(trim($iniValue)); - $unit = strtolower(array_pop($iniValues)); - $quantity = (int) implode($iniValues); - switch ($unit) { - case 'g': - $quantity *= 1024; - // deliberate no break - case 'm': - $quantity *= 1024; - // deliberate no break - case 'k': - $quantity *= 1024; - // deliberate no break - default: - // no-op: pre-existing behaviour - break; + // Remove non-unit characters from the size + $unit = preg_replace('/[^bkmgtpezy]/i', '', $iniValue); + // Remove non-numeric characters from the size + $size = preg_replace('/[^0-9\.]/', '', $iniValue); + + if ($unit) { + // Find the position of the unit in the ordered string which is the power + // of magnitude to multiply a kilobyte by + $size = round($size * pow(1024, stripos('bkmgtpezy', $unit[0]))); + } else { + $size = round($size); } - return $quantity; + + // Cast to int - round() returns a float + return (int)$size; } /** diff --git a/tests/filesystem/FileTest.php b/tests/filesystem/FileTest.php index b2ecf5e83..5df3050f6 100644 --- a/tests/filesystem/FileTest.php +++ b/tests/filesystem/FileTest.php @@ -413,6 +413,33 @@ class FileTest extends SapphireTest { $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() {