From 300cc8b8b2810dd8b2ec8063c12eda3e41afe10b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 18 Jul 2017 14:07:55 +0200 Subject: [PATCH 1/2] Factor out code for MIME tranformations mapping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue #1347 Signed-off-by: Michal Čihař --- libraries/transformations.lib.php | 52 +++++++++++++++++-------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/libraries/transformations.lib.php b/libraries/transformations.lib.php index e100013078..03fd7b243d 100644 --- a/libraries/transformations.lib.php +++ b/libraries/transformations.lib.php @@ -201,6 +201,32 @@ function PMA_getTransformationName($file) return $class_name::getName(); } +/** + * Fixups old MIME or tranformation name to new one + * + * @param string $value Value to fixup + * + * @return string + */ +function PMA_fixupMIME($value) +{ + $delimiter_space = '- '; + $delimiter = "_"; + $value = str_replace("jpeg", "JPEG", $value); + $value = str_replace("png", "PNG", $value); + return str_replace( + $delimiter_space, + $delimiter, + ucwords( + str_replace( + $delimiter, + $delimiter_space, + $value + ) + ) + ); +} + /** * Gets the mimetypes for all columns of a table * @@ -253,19 +279,7 @@ function PMA_getMIME($db, $table, $strict = false, $fullName = false) $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'] = PMA_fixupMIME($values['mimetype']); // For transformation of form // output/image_jpeg__inline.inc.php @@ -277,17 +291,7 @@ function PMA_getMIME($db, $table, $strict = false, $fullName = false) $values['transformation'] = $dir[1]; } - $values['transformation'] = str_replace( - $delimiter_space, - $delimiter, - ucwords( - str_replace( - $delimiter, - $delimiter_space, - $values['transformation'] - ) - ) - ); + $values['transformation'] = PMA_fixupMIME($values['transformation']); $values['transformation'] = $subdir . $values['transformation']; $result[$column] = $values; } From b7788850a9f545dd693d476f51349096c83426cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 18 Jul 2017 14:18:02 +0200 Subject: [PATCH 2/2] Fixed usage of some browser transformations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #13478 Signed-off-by: Michal Čihař --- ChangeLog | 1 + libraries/transformations.lib.php | 22 +++++++-------- test/libraries/PMA_transformation_test.php | 33 ++++++++++++++++++++++ 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 89c8b85a6c..baaad95aa3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,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/transformations.lib.php b/libraries/transformations.lib.php index 03fd7b243d..c9437d7cf7 100644 --- a/libraries/transformations.lib.php +++ b/libraries/transformations.lib.php @@ -204,25 +204,25 @@ function PMA_getTransformationName($file) /** * 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 */ function PMA_fixupMIME($value) { - $delimiter_space = '- '; - $delimiter = "_"; - $value = str_replace("jpeg", "JPEG", $value); - $value = str_replace("png", "PNG", $value); + $value = str_replace( + array("jpeg", "png"), array("JPEG", "PNG"), $value + ); return str_replace( - $delimiter_space, - $delimiter, + ' ', + '', ucwords( - str_replace( - $delimiter, - $delimiter_space, - $value - ) + preg_replace('/([0-9_]+)/', '$1 ', $value) ) ); } diff --git a/test/libraries/PMA_transformation_test.php b/test/libraries/PMA_transformation_test.php index 0ca247be72..5e33e414a0 100644 --- a/test/libraries/PMA_transformation_test.php +++ b/test/libraries/PMA_transformation_test.php @@ -255,4 +255,37 @@ class PMA_Transformation_Test extends PHPUnit_Framework_TestCase $actual ); } + + /** + * @dataProvider fixupData + */ + public function testFixup($value, $expected) + { + $this->assertEquals( + $expected, + PMA_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' + ), + ); + } }