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

FileUpload: fix getters calls on empty FileUpload #195

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

EdaCZ
Copy link

@EdaCZ EdaCZ commented Mar 26, 2021

  • bug fix: yes
  • BC break: no

This happened to me recently: I forgot to mark form item with file upload as mandatory, so users were able to send form without any file. But on backend I have complex system of validators, which want to validate name, size etc. Validators are build using composition and each of them do just one thing (for example one of them just calls getName (newly getSanitizedName / getUntrustedName) on received FileUpload and checks its name...). It's not really handy to repeat in each of them condition with $file->isOk()... But if I didn't have it there, it would crash on the error: Return value of Nette\Http\FileUpload::getName() must be of the type string, null returned (in PHP 7.3), because properties don't have default values and null is not compatible with typehint string...

I believe that getters should be callable without an error even on empty file upload, to make behavior of our FileUpload more predictable and consistent.

I tried to add failing test and fix it.

I hope it's ok for you, just let me know if some changes needed.

Thanks.

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

3 participants