From e8c4a7e56e6329860fc17c07a613af55e5f0bfcb Mon Sep 17 00:00:00 2001 From: Tobias Munk Date: Mon, 4 Sep 2023 10:09:49 +0200 Subject: [PATCH] added PHP version check, fixed #19925 (#19936) * added PHP version check, fixed #19925 * added CHANGELOG line * fixed typo * fixed typo --------- Co-authored-by: Alexander Makarov Co-authored-by: Bizley --- framework/CHANGELOG.md | 1 + framework/helpers/mimeTypes.php | 3 ++- tests/framework/helpers/MimeTest.php | 3 ++- tests/framework/validators/FileValidatorTest.php | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index a96d0eff96e..95d436776de 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -4,6 +4,7 @@ Yii Framework 2 Change Log 2.0.50 under development ------------------------ +- Bug #19925: Improved PHP version check when handling MIME types (schmunk42) - Bug #19940: File Log writer without newline (terabytesoftw) diff --git a/framework/helpers/mimeTypes.php b/framework/helpers/mimeTypes.php index 707bdc7717e..e91f80f95f8 100644 --- a/framework/helpers/mimeTypes.php +++ b/framework/helpers/mimeTypes.php @@ -1003,7 +1003,8 @@ 'zmm' => 'application/vnd.handheld-entertainment+xml', ]; -if (PHP_VERSION_ID >= 80100) { +# fix for bundled libmagic bug, see also https://github.com/yiisoft/yii2/issues/19925 +if ((PHP_VERSION_ID >= 80100 && PHP_VERSION_ID < 80122) || (PHP_VERSION_ID >= 80200 && PHP_VERSION_ID < 80209)) { $mimeTypes = array_replace($mimeTypes, array('xz' => 'application/octet-stream')); } diff --git a/tests/framework/helpers/MimeTest.php b/tests/framework/helpers/MimeTest.php index 2c0d8f09de2..b3914d5a11b 100644 --- a/tests/framework/helpers/MimeTest.php +++ b/tests/framework/helpers/MimeTest.php @@ -1031,7 +1031,8 @@ public function testMimeTypes() 'zmm' => 'application/vnd.handheld-entertainment+xml', ]; - if (PHP_VERSION_ID >= 80100) { + # fix for bundled libmagic bug, see also https://github.com/yiisoft/yii2/issues/19925 + if ((PHP_VERSION_ID >= 80100 && PHP_VERSION_ID < 80122) || (PHP_VERSION_ID >= 80200 && PHP_VERSION_ID < 80209)) { $coreMimeTypes = array_replace($coreMimeTypes, array('xz' => 'application/octet-stream')); } diff --git a/tests/framework/validators/FileValidatorTest.php b/tests/framework/validators/FileValidatorTest.php index f6af4ec6816..157269e5d41 100644 --- a/tests/framework/validators/FileValidatorTest.php +++ b/tests/framework/validators/FileValidatorTest.php @@ -546,7 +546,8 @@ public function validMimeTypes() ['test.tar.xz', 'application/x-xz', 'tar.xz'], ]); - if (PHP_VERSION_ID >= 80100) { + # fix for bundled libmagic bug, see also https://github.com/yiisoft/yii2/issues/19925 + if ((PHP_VERSION_ID >= 80100 && PHP_VERSION_ID < 80122) || (PHP_VERSION_ID >= 80200 && PHP_VERSION_ID < 80209)) { $v81_zx = ['test.tar.xz', 'application/octet-stream', 'tar.xz']; array_pop($validMimeTypes); $validMimeTypes[] = $v81_zx;