-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Use getPathname() instead of string casting to get BinaryFileReponse file path #11837
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
Conversation
According to the code, should be "File" instead of "\SplFileInfo"
Removing |
Ok, let's try to disambiguate the situation. I think, we should check the instance of file, and in case of \SplFileInfo, use the getPathName() method instead of string casting |
then we should fix the way we get the path name for SplFileInfo to support the SplFileObject child class. This is actually a bug. Btw, the fact that SplFileObject::__toString() can return an array should be reported as a PHP bug IMO |
Ok, i've updated the pr. |
Please add a test using SplFileObject to avoid regressions |
Done :) |
👍 |
|
||
$response = new BinaryFileResponse($file); | ||
|
||
$this->assertEquals($response->getfile()->getPathname(), $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.
This test will fail on Windows because of directory separator mismatch
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.
@stof well, all of the BinaryFileResponseTest tests are based on such paths...
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.
nope. None of the other tests is doing an assertion on $response->getfile()->getPathname()
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.
Ah, sorry, i didn't get it.
I will fix that.
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.
By the way, the "f" in getFile()
should be upper-cased.
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.
Ooops, nice catch !
Ok, using realpath should do the trick. |
Thank you @nervo. |
…ileReponse file path (nervo) This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #11837). Discussion ---------- Use getPathname() instead of string casting to get BinaryFileReponse file path According to the code, should be "File" instead of "\SplFileInfo" Commits ------- e1eb788 Use getPathname() instead of string casting to get BinaryFileReponse file path
According to the code, should be "File" instead of "\SplFileInfo"