-
Notifications
You must be signed in to change notification settings - Fork 45
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 moving uploaded file crashed when source was stream #171
Conversation
I have problem of creating meaningful test in order to improve the code coverage. I kind of recognize too much duplications. I was thinking that maybe I should restructure the I recognize three possible scenarios how to apply the movement behavior:
The SAPI would be first because PSR-7 documentation states:
Then if source and destination are files, then moving file would be most efficient. All others will be moved as streams. If parameter is file (or uri), it is opened using Also noticed that there are test cases that cover cases when Before making this effort would like to have blessing from author. |
I think that we should do something similar to: |
In case of error the stream_copy_to_stream will throw it's own exception that tells in more detail what went wrong.
Line UploadedFile.php ------ ----------------------------------------------------------------------------------------------- 175 Parameter slimphp#1 $source of function stream_copy_to_stream expects resource, resource|null given. 175 Parameter slimphp#2 $dest of function stream_copy_to_stream expects resource, resource|false given.
Line UploadedFile.php ------ ---------------------------------------------------------------------------------------------- 179 Parameter slimphp#2 $dest of function stream_copy_to_stream expects resource, resource|false given. 181 Parameter slimphp#1 $fp of function fclose expects resource, resource|false given. ------ ---------------------------------------------------------------------------------------------- Had to force to skip target writability test in order to conduct a test that PHPStan required in a way that the 100% code coverage would be remain intact.
Probably yes, but I decided to fix only the original bug. Current code works, refactoring has always risks. Better to leave it in case there is major improvement planned. Currently managed to make tests that covered checks that where required by PHPStan. |
Ready for review and merge. Only one PHPStan warning remained which, turns out, exists in master also.
|
I'm closing this as stale. Feel free to reopen. |
Description
When UploadedFile is created from stream then calling
movingTo
will throw an exception.Script to reproduce the bug
Expected output:
Hello, World!
Actual output:
Motivation
I discovered this bug when I was creating a stub for a test.
Notes on implementation
I used
stream_copy_to_stream
for copying. I speculate that built-in stream function should be more efficient because it is implemented in C.My fix also handles
php://temp
case where huge files might be the case.