diff --git a/ChangeLog b/ChangeLog index 1f9551cd1e..a7024adc16 100644 --- a/ChangeLog +++ b/ChangeLog @@ -40,6 +40,7 @@ phpMyAdmin - ChangeLog - issue #13468 Avoid breakage if set_time_limit is disabled - issue #13471 Fail if ini_set/ini_get are disabled - issue #13436 Automatically connect using SSL when server is configured so +- issue #13478 Fixed usage of some browser transformations 4.7.2 (2017-06-29) - issue #13314 Make theme selection keep current server diff --git a/libraries/classes/Transformations.php b/libraries/classes/Transformations.php index 29dc1a703c..5f33c646f4 100644 --- a/libraries/classes/Transformations.php +++ b/libraries/classes/Transformations.php @@ -209,6 +209,32 @@ class Transformations return $class_name::getName(); } + /** + * Fixups old MIME or tranformation name to new one + * + * - applies some hardcoded fixups + * - adds spaces after _ and numbers + * - capitalizes words + * - removes back spaces + * + * @param string $value Value to fixup + * + * @return string + */ + static function fixupMIME($value) + { + $value = str_replace( + array("jpeg", "png"), array("JPEG", "PNG"), $value + ); + return str_replace( + ' ', + '', + ucwords( + preg_replace('/([0-9_]+)/', '$1 ', $value) + ) + ); + } + /** * Gets the mimetypes for all columns of a table * @@ -256,24 +282,10 @@ class Transformations ); foreach ($result as $column => $values) { - // replacements in mimetype and transformation - $values = str_replace("jpeg", "JPEG", $values); - $values = str_replace("png", "PNG", $values); - // convert mimetype to new format (f.e. Text_Plain, etc) $delimiter_space = '- '; $delimiter = "_"; - $values['mimetype'] = str_replace( - $delimiter_space, - $delimiter, - ucwords( - str_replace( - $delimiter, - $delimiter_space, - $values['mimetype'] - ) - ) - ); + $values['mimetype'] = self::fixupMIME($values['mimetype']); // For transformation of form // output/image_jpeg__inline.inc.php @@ -285,17 +297,7 @@ class Transformations $values['transformation'] = $dir[1]; } - $values['transformation'] = str_replace( - $delimiter_space, - $delimiter, - ucwords( - str_replace( - $delimiter, - $delimiter_space, - $values['transformation'] - ) - ) - ); + $values['transformation'] = self::fixupMIME($values['transformation']); $values['transformation'] = $subdir . $values['transformation']; $result[$column] = $values; } diff --git a/test/classes/TransformationsTest.php b/test/classes/TransformationsTest.php index e1af2624f1..437800944d 100644 --- a/test/classes/TransformationsTest.php +++ b/test/classes/TransformationsTest.php @@ -254,4 +254,37 @@ class TransformationsTest extends PHPUnit_Framework_TestCase $actual ); } + + /** + * @dataProvider fixupData + */ + public function testFixup($value, $expected) + { + $this->assertEquals( + $expected, + Transformations::fixupMIME($value) + ); + } + + public function fixupData() + { + return array( + array( + 'text_plain_bool2text.php', + 'Text_Plain_Bool2Text.php' + ), + array( + 'application_octetstream_download.php', + 'Application_Octetstream_Download.php' + ), + array( + 'text_plain_json.php', + 'Text_Plain_Json.php' + ), + array( + 'image_jpeg_link.php', + 'Image_JPEG_Link.php' + ), + ); + } }