Skip to content
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

Fix a validation issue on multiple file upload #2265

Merged
merged 6 commits into from Sep 26, 2019
Merged

Fix a validation issue on multiple file upload #2265

merged 6 commits into from Sep 26, 2019

Conversation

pjsde
Copy link
Contributor

@pjsde pjsde commented Sep 25, 2019

Fix a validation issue on multiple file upload mentionate in #2175

  1. A function has been created in FileCollection where it will return null if it does not find the uploaded file or else return an array of multiple uploaded files so that a multiple upload can be validated.

  2. Then the validation rules were changed so that it was checked first if the upload had been set with multiple files and if it was then validate all uploaded files returning error if any of them did not verify the rule.

Checklist:

  • Securely signed commits
  • Component(s) with PHPdocs
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@MGatner
Copy link
Member

MGatner commented Sep 25, 2019

This looks like a nice expansion on uploads. One of the admins should look over it as well but in the meantime it will definitely need some tests and updates to the User Guide:

  • user_guide_src/source/incoming/incomingrequest.rst
  • user_guide_src/source/libraries/uploaded_files.rst
  • user_guide_src/source/libraries/validation.rst

If you want help editing or reviewing those I would be glad to assist.

Copy link
Member

@lonnieezell lonnieezell left a comment

Choose a reason for hiding this comment

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

I'm like this addition. I had one comment where I think you'll hit an exception if multiple files exist.

Definitely need tests and docs updates as @MGatner said.


if ($this->hasFile($name))
{
if (strpos($name, '.') !== false)
Copy link
Member

Choose a reason for hiding this comment

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

Pretty sure this needs an is_string() check before. An array would throw an exception under strpos.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesnt need is_string() because $name is a string not an arrary.

Copy link
Member

Choose a reason for hiding this comment

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

Doh! You're correct. Sorry, confused it when I saw the is_array check below. My bad for scanning too quickly.

@pjsde
Copy link
Contributor Author

pjsde commented Sep 25, 2019

@MGatner it will be awesome if you could help with the editing/reviewing of the User Guide.

I will try to write some tests to validate the changes.

@pjsde
Copy link
Contributor Author

pjsde commented Sep 25, 2019

By the way, I need some help with the following: I installed PHPUnit to be able to create and run the tests and detected that there are errors with the setUp() and tearDown() function definition. They should be as defined in the class TestCase:setUp():void / TestCase:tearDown():void.

I think there must have been an update in the TestCase class from PHPUnit where the return type was explicity declared as :void. I've already updated all classes that override these functions and added the return type: void to them.

Now my question is whether I should commit these changes to your framework or should I keep them local?

@lonnieezell
Copy link
Member

I remember seeing that error previously, but I believe it had to do with the version of PHPUnit that was being used. It's been a while, though. For now - keep those locally.

Do you use a global PHPUnit install? If you use composer to install the dev dependencies locally it will provide the version that the framework is tested with in the vendor folder so vendor/phpunit/phpunit would be the command I believe. I've got a global alias setup that always expects to find it at that location so I just have to run phpu from the base of any of my apps. Long way of saying I may have that path wrong :)

@pjsde
Copy link
Contributor Author

pjsde commented Sep 25, 2019

I'm not using a global installation. I did the installation with the composer but it must have gone wrong so I will have to see later then.

I will leave it locally and then see what happened and if i've installed a wrong version of PHPUnit.

Thanks

@pjsde
Copy link
Contributor Author

pjsde commented Sep 25, 2019

I've just added now 5 tests to check getFileMultiple(). If you can see if its necessary more tests or even if this ones are ok, i'll apreciate.
Thanks

@jim-parry jim-parry merged commit 7e3d262 into codeigniter4:develop Sep 26, 2019
@MGatner
Copy link
Member

MGatner commented Sep 26, 2019

I’m okay with this merge but let’s be sure the User Guide gets an update at some point.

@jim-parry
Copy link
Contributor

Agreed. There are a couple of user guide updates in the works as housekeepig prep for rc.2 :)

@pjsde pjsde deleted the fix_uploadfiles branch September 26, 2019 21:07
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.

None yet

4 participants