Skip to content

Commit

Permalink
Merge pull request codeigniter4#4054 from michalsn/rar-mime-type-update
Browse files Browse the repository at this point in the history
Add mime type for rar files
  • Loading branch information
michalsn authored and mostafakhudair committed Jan 16, 2021
2 parents 2a0d39f + 5ab717a commit 129ce36
Show file tree
Hide file tree
Showing 147 changed files with 6,495 additions and 6,394 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/test-phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,26 @@ on:
paths:
- 'app/**'
- 'system/**'
- phpstan.neon.dist
push:
branches:
- 'develop'
- '4.*'
paths:
- 'app/**'
- 'system/**'
- phpstan.neon.dist

jobs:
build:
name: PHP ${{ matrix.php-versions }} Static Analysis
name: Analyze code (PHPStan)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: ['7.4', '8.0']
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
php-version: '7.4'
extensions: intl

- name: Use latest Composer
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0']
php-versions: ['7.2', '7.3', '7.4']
db-platforms: ['MySQLi', 'Postgre', 'SQLite3', 'SQLSRV']

services:
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
with:
php-version: ${{ matrix.php-versions }}
tools: composer, pecl
extensions: imagick, sqlsrv-beta
extensions: imagick, sqlsrv
coverage: xdebug
env:
update: true
Expand Down
6 changes: 0 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
- `CodeIgniter\Config\Config` is now deprecated in favor of `CodeIgniter\Config\Factories::config()`
- HTTP Layer Refactor: Numerous deprecations have been made towards a transition to a PSR-compliant HTTP layer. [See the User Guide](user_guide_src/source/installation/upgrade_405.rst)

**Mime Type Detection**

- `Config\Mimes::guessExtensionFromType` now only reverse searches the `$mimes` array if no extension is proposed (i.e., usually not for uploaded files).
- The fallback values of `UploadedFile->getExtension()` and `UploadedFile->guessExtension()` have been changed. `UploadedFile->getExtension()` now returns `$this->getClientExtension()` instead of `''`; `UploadedFile->guessExtension()` now returns `''` instead of `$this->getClientExtension()`.
These changes increase security when handling uploaded files as the client can no longer force a wrong mime type on the application. However, these might affect how file extensions are detected in your application.

## [v4.0.4](https://github.com/codeigniter4/CodeIgniter4/tree/v4.0.4) (2020-07-15)

[Full Changelog](https://github.com/codeigniter4/CodeIgniter4/compare/v4.0.3...v4.0.4)
Expand Down
3 changes: 0 additions & 3 deletions admin/framework/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
"predis/predis": "^1.1",
"squizlabs/php_codesniffer": "^3.3"
},
"suggest": {
"ext-fileinfo": "Improves mime type detection for files"
},
"autoload": {
"psr-4": {
"CodeIgniter\\": "system/"
Expand Down
3 changes: 0 additions & 3 deletions admin/module/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
"mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "^8.5"
},
"suggest": {
"ext-fileinfo": "Improves mime type detection for files"
},
"autoload-dev": {
"psr-4": {
"Tests\\Support\\": "tests/_support"
Expand Down
3 changes: 0 additions & 3 deletions admin/starter/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
"mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "^8.5"
},
"suggest": {
"ext-fileinfo": "Improves mime type detection for files"
},
"autoload": {
"psr-4": {
"App\\": "app",
Expand Down
16 changes: 0 additions & 16 deletions app/Config/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class Cache extends BaseConfig
* system.
*
* @var string
*
* @deprecated Use the driver-specific variant under $file
*/
public $storePath = WRITEPATH . 'cache/';

Expand Down Expand Up @@ -82,20 +80,6 @@ class Cache extends BaseConfig
*/
public $prefix = '';

/**
* --------------------------------------------------------------------------
* File settings
* --------------------------------------------------------------------------
* Your file storage preferences can be specified below, if you are using
* the File driver.
*
* @var array<string, string|int|null>
*/
public $file = [
'storePath' => WRITEPATH . 'cache/',
'mode' => 0640,
];

/**
* -------------------------------------------------------------------------
* Memcached settings
Expand Down
16 changes: 8 additions & 8 deletions app/Config/Generators.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ class Generators extends BaseConfig
* @var array<string, string>
*/
public $views = [
'make:command' => 'CodeIgniter\\Commands\\Generators\\Views\\command.tpl.php',
'make:controller' => 'CodeIgniter\\Commands\\Generators\\Views\\controller.tpl.php',
'make:entity' => 'CodeIgniter\\Commands\\Generators\\Views\\entity.tpl.php',
'make:filter' => 'CodeIgniter\\Commands\\Generators\\Views\\filter.tpl.php',
'make:migration' => 'CodeIgniter\\Commands\\Generators\\Views\\migration.tpl.php',
'make:model' => 'CodeIgniter\\Commands\\Generators\\Views\\model.tpl.php',
'make:seeder' => 'CodeIgniter\\Commands\\Generators\\Views\\seed.tpl.php',
'session:migration' => 'CodeIgniter\\Commands\\Generators\\Views\\session_migration.tpl.php',
'make:command' => 'CodeIgniter\Commands\Generators\Views\command.tpl.php',
'make:controller' => 'CodeIgniter\Commands\Generators\Views\controller.tpl.php',
'make:entity' => 'CodeIgniter\Commands\Generators\Views\entity.tpl.php',
'make:filter' => 'CodeIgniter\Commands\Generators\Views\filter.tpl.php',
'make:migration' => 'CodeIgniter\Commands\Generators\Views\migration.tpl.php',
'make:model' => 'CodeIgniter\Commands\Generators\Views\model.tpl.php',
'make:seeder' => 'CodeIgniter\Commands\Generators\Views\seeder.tpl.php',
'session:migration' => 'CodeIgniter\Commands\Generators\Views\session_migration.tpl.php',
];
}
20 changes: 6 additions & 14 deletions app/Config/Mimes.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
* the most common one should be first in the array to aid the guess*
* methods. The same applies when more than one mime-type exists for a
* single extension.
*
* When working with mime types, please make sure you have the ´fileinfo´
* extension enabled to reliably detect the media types.
*/

class Mimes
Expand All @@ -36,6 +33,7 @@ class Mimes
'text/csv',
'text/x-comma-separated-values',
'text/comma-separated-values',
'application/octet-stream',
'application/vnd.ms-excel',
'application/x-csv',
'text/x-csv',
Expand Down Expand Up @@ -71,6 +69,7 @@ class Mimes
'application/pdf',
'application/force-download',
'application/x-download',
'binary/octet-stream',
],
'ai' => [
'application/pdf',
Expand Down Expand Up @@ -463,10 +462,12 @@ class Mimes
'srt' => [
'text/srt',
'text/plain',
'application/octet-stream',
],
'vtt' => [
'text/vtt',
'text/plain',
'application/octet-stream',
],
'ico' => [
'image/x-icon',
Expand Down Expand Up @@ -508,20 +509,11 @@ public static function guessExtensionFromType(string $type, string $proposedExte

$proposedExtension = trim(strtolower($proposedExtension));

if ($proposedExtension !== '')
if ($proposedExtension !== '' && array_key_exists($proposedExtension, static::$mimes) && in_array($type, is_string(static::$mimes[$proposedExtension]) ? [static::$mimes[$proposedExtension]] : static::$mimes[$proposedExtension], true))
{
if(array_key_exists($proposedExtension, static::$mimes) && in_array($type, is_string(static::$mimes[$proposedExtension]) ? [static::$mimes[$proposedExtension]] : static::$mimes[$proposedExtension], true))
{
// The detected mime type matches with the proposed extension.
return $proposedExtension;
}

// An extension was proposed, but the media type does not match the mime type list.
return null;
return $proposedExtension;
}

// Reverse check the mime type list if no extension was proposed.
// This search is order sensitive!
foreach (static::$mimes as $ext => $types)
{
if ((is_string($types) && $types === $type) || (is_array($types) && in_array($type, $types, true)))
Expand Down
10 changes: 3 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@
"codeigniter4/codeigniter4-standard": "^1.0",
"fakerphp/faker": "^1.9",
"mikey179/vfsstream": "^1.6",
"phpstan/phpstan": "0.12.65",
"phpunit/phpunit": "^8.5 || ^9.1",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^8.5",
"predis/predis": "^1.1",
"rector/rector": "^0.8",
"squizlabs/php_codesniffer": "^3.3"
},
"suggest": {
"ext-fileinfo": "Improves mime type detection for files"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
Expand All @@ -39,8 +36,7 @@
},
"autoload-dev": {
"psr-4": {
"CodeIgniter\\": "tests/system/",
"Utils\\": "utils/"
"Utils\\": "utils"
}
},
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ parameters:
- system/Config/Routes.php
- system/Debug/Toolbar/Views/toolbar.tpl.php
- system/Images/Handlers/GDHandler.php
- system/Test/Filters/CITestStreamFilter.php
- system/ThirdParty/*
- system/Validation/Views/single.php
ignoreErrors:
Expand Down
Loading

0 comments on commit 129ce36

Please sign in to comment.