Skip to content

[9.x] Avoid throwing on invalid mime-type#42761

Merged
taylorotwell merged 2 commits into
laravel:9.xfrom
rodrigopedra:do-not-throw-on-invalid-mimetype
Jun 13, 2022
Merged

[9.x] Avoid throwing on invalid mime-type#42761
taylorotwell merged 2 commits into
laravel:9.xfrom
rodrigopedra:do-not-throw-on-invalid-mimetype

Conversation

@rodrigopedra

@rodrigopedra rodrigopedra commented Jun 11, 2022

Copy link
Copy Markdown
Contributor

league/flysystem version 3, changed to throw exceptions in places it previously returned null or false when a called method failed to execute.

As noted by issue #42758 , calling Illuminate\Filesystem\FilesystemAdapter@mimeType throws an exception when a file has a custom extension.

This becomes a problem when this method is called within other methods such in:

Disclaimer: usage on Illuminate\Filesystem\FilesystemAdapter@response is changed to be lazily evaluated in PR #42760

This PR

  • Changes Illuminate\Filesystem\FilesystemAdapter@mimeType to return false, as per its docblock, when the mime type cannot be detected
  • Honors the throw configuration, when a developer sets it to true an exception will be thrown instead
  • Adds two test cases covering both cases

EDIT

As league/flysystem changed the mime type detection behavior on tag 3.0.16, I updated the composer.json file to require at least this version.

Otherwise tests with prefer-lowest were failing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants