-
Notifications
You must be signed in to change notification settings - Fork 87
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
Enforce string for folder id when obtaining the trash folder #1472
Conversation
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.
LGTM
groupfolders/lib/Trash/TrashBackend.php Lines 270 to 272 in 6633e64
To use strict types later we may cast the folder id to a string here. However i'm a bit supprised to see $folderId as integer here as the value comes from the database and should be a string. |
Looks like we already cast the id to int right after we get it from the db: groupfolders/lib/Folder/FolderManager.php Line 418 in 6e6d353
|
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.
Casting the types back and forth (the folder id is originally a string when it is retrieved from the db) in several places seems kind of messy, but cleaning this is out of scope of this PR.
In groupfolders it's okay to treat the folderId as integer. As soon as we use the folderId to access the filesystem the folderId must be a string (because the filesystem api expects a string). A string typehint for getTrashFolder tell's php to convert the method parameter to a string. But only if strict types are not enabled for the current file. The goal is to have more files with strict code. Adding a cast to string before calling the typed method ensures that the code still works with strict mode enabled. groupfolders/lib/Trash/TrashBackend.php Line 270 in 6633e64
|
Ok, sounds reasonable. But then it looks like there is at least one more case where groupfolders/lib/Trash/TrashBackend.php Lines 323 to 326 in 7d7abd6
|
Yep. As getTrashFolder is a groupfolder method it would also work to typehint the method to int and cast the string inside getTrashFolder. |
@juliushaertl Could you improve this according to the suggestion from @kesselb? Thanks! |
Anyway we can get this on the next release ? |
bccc7d4
to
ab69b1e
Compare
Adjusted accordingly to always use an int internally and only cast to string when referring to the nodes API. I also added a cast to avoid possible further string occurences when building the folder array from the database results. |
Signed-off-by: Julius Härtl <jus@bitgrid.net>
ab69b1e
to
3781b7c
Compare
/backport to stable21 |
/backport to stable20 |
/backport to stable19 |
Fix for #907 (comment)