-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IBX-6856: Added mime types limitation for ezimage field type #300
IBX-6856: Added mime types limitation for ezimage field type #300
Conversation
src/lib/FieldType/Image/Type.php
Outdated
@@ -36,14 +36,29 @@ class Type extends FieldType implements TranslationContainerInterface | |||
], | |||
]; | |||
|
|||
/** @var array<string, array<array<mixed>|scalar>> */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to properly define array shape here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed: 2e03387
@@ -98,7 +99,7 @@ abstract public function validateConstraints($constraints); | |||
* | |||
* @return bool | |||
*/ | |||
abstract public function validate(Value $value); | |||
abstract public function validate(Value $value, ?FieldDefinition $fieldDefinition = null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
This is not an internal class, but it hasn't been documented as an SPI either, so I would just add a note in the upgrade/release notes that this method got an extra parameter (If it were an SPI it would be a breaking change).
{ | ||
// silence `getimagesize` error as extension-wise valid image files might produce it anyway | ||
// note that file extension checking is done using other validation which should be called before this one | ||
if (!@getimagesize($filePath)) { | ||
if (!$imageData = @getimagesize($filePath)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what kind / types of values causes !$imageData
to evaluate to true or false? Can we be always more strict? As a reminder !'0'
evaluates to true and yet it is some sort of data ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!$imageData = @getimagesize($filePath)) { | |
$imageData = @getimagesize($filePath); | |
if ($imageData !== false) { |
Negation of variable assignment inside of condition can be confusing and less readable expression. It is better to avoid it in a first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
] | ||
); | ||
} | ||
|
||
/** | ||
* @return array<string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
either I'm reading the method wrong, or this is not correct. I wonder why we don't have anything on this from PHPStan. In pure playground environment it reports here an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ | ||
// silence `getimagesize` error as extension-wise valid image files might produce it anyway | ||
// note that file extension checking is done using other validation which should be called before this one | ||
if (!@getimagesize($filePath)) { | ||
if (!$imageData = @getimagesize($filePath)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!$imageData = @getimagesize($filePath)) { | |
$imageData = @getimagesize($filePath); | |
if ($imageData !== false) { |
Negation of variable assignment inside of condition can be confusing and less readable expression. It is better to avoid it in a first place.
tests/integration/Core/Repository/FieldType/ImageIntegrationTest.php
Outdated
Show resolved
Hide resolved
tests/integration/Core/Repository/FieldType/ImageIntegrationTest.php
Outdated
Show resolved
Hide resolved
tests/integration/Core/Repository/FieldType/ImageIntegrationTest.php
Outdated
Show resolved
Hide resolved
32ecebe
to
c44b948
Compare
Co-authored-by: Maciej Kobus <[email protected]>
c44b948
to
6cd0d98
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
v4.6
Requires:
ibexa/admin-ui#1021
ibexa/content-forms#55
https://github.com/ibexa/image-editor/pull/80
This PR adds
mimeTypes
field setting to store which mime types are allowed for Image Field type. If empty array then all image mime types are allowed.There is also added
ibexa.field_type.ezimage.mime_types
parameter with predefined mime type list that will be displayed in Image Field type definition.Checklist:
$ composer fix-cs
).@ibexa/engineering
).