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

Enforce string for folder id when obtaining the trash folder #1472

Merged
merged 1 commit into from
Jun 17, 2021

Conversation

juliushaertl
Copy link
Member

Fix for #907 (comment)

Copy link
Member

@solracsf solracsf left a comment

Choose a reason for hiding this comment

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

LGTM

@kesselb
Copy link
Contributor

kesselb commented Apr 28, 2021

$folderId = $folder['folder_id'];
$mountPoint = $folder['mount_point'];
$trashFolder = $this->getTrashFolder($folderId);

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.

@fschrempf
Copy link
Contributor

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:

'folder_id' => (int)$folder['folder_id'],

Copy link
Contributor

@fschrempf fschrempf left a 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.

@kesselb
Copy link
Contributor

kesselb commented May 14, 2021

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.

$folderId = $folder['folder_id'];

$folderId = (string)$folder['folder_id']; and it will also work with strict mode.

@fschrempf
Copy link
Contributor

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.

Ok, sounds reasonable. But then it looks like there is at least one more case where getTrashFolder() is called with an int parameter. I guess this needs to be fixed, too:

public function cleanTrashFolder(int $folderid) {
$trashFolder = $this->getTrashFolder($folderid);
if (!($trashFolder instanceof Folder)) {

@kesselb
Copy link
Contributor

kesselb commented May 14, 2021

Yep. As getTrashFolder is a groupfolder method it would also work to typehint the method to int and cast the string inside getTrashFolder.

@fschrempf
Copy link
Contributor

@juliushaertl Could you improve this according to the suggestion from @kesselb? Thanks!

@AndyXheli
Copy link

Anyway we can get this on the next release ?

@juliushaertl juliushaertl force-pushed the bugfix/noid/trash-folderid-string branch from bccc7d4 to ab69b1e Compare June 17, 2021 11:02
@juliushaertl
Copy link
Member Author

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.

@juliushaertl juliushaertl force-pushed the bugfix/noid/trash-folderid-string branch from ab69b1e to 3781b7c Compare June 17, 2021 11:07
@kesselb kesselb merged commit ef478f3 into master Jun 17, 2021
@kesselb kesselb deleted the bugfix/noid/trash-folderid-string branch June 17, 2021 15:26
@juliushaertl
Copy link
Member Author

/backport to stable21

@juliushaertl
Copy link
Member Author

/backport to stable20

@juliushaertl
Copy link
Member Author

/backport to stable19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Items that need to be reviewed bug
Projects
None yet
5 participants