Skip to content

Conversation

dan-steele
Copy link

Hey,

The upload blows up with an InvalidArgumentException when I have the following set in the table

$this->addBehavior('Josegonzalez/Upload.Upload', ['file']);

because $settings gets passed as null and Hash::get doesn't handle it properly. It works find when I do

$this->addBehavior('Josegonzalez/Upload.Upload', ['file' => []]);

but I think it's better to handle it here.

continue;
}

$settings = ($settings === null) ? [] : $settings;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

$settings = $settings ?: [];

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:
$settings = is_array($settings) ? $settings : [];
to prevent
['field' => true]
from passing and giving errors afterwards

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me. Can you add a test for that?

@josegonzalez
Copy link
Member

@dan-steele bump

@jorisvaesen
Copy link
Collaborator

After some testing if found out this issue actually starts at initialize().
When passing in settings as ['field'], it actually becomes [0 => 'field', 'field' => null] after.
So i guess the config should be dropped before this line: https://github.com/josegonzalez/cakephp-upload/blob/master/src/Model/Behavior/UploadBehavior.php#L28

@josegonzalez
Copy link
Member

Closed by #378

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

Successfully merging this pull request may close these issues.

4 participants