Close array key gaps in returned arrays
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 36.9k
- Forks
- 5.2k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 713
Description
In a lot of places we take the first mount point, first node, etc.
The issue is, that the returned results are handled by array_filter before.
https://github.com/nextcloud/server/blob/b29baababdbc56b1633eca2d8357dd6b87268050/lib/private/Files/Config/UserMountCache.php#L297
https://github.com/nextcloud/server/blob/6fbe991afbb5df36c2fef5cac8c9681f91aed311/lib/private/Files/Node/Folder.php#L326
The problem with that is, that [0] may be undefined. There is currently a bug open in the retention repo: https://github.com/nextcloud/files_retention/pull/38
While this can be easily fixed on the consumer side: https://github.com/nextcloud/files_retention/pull/39
I think we should array_values all the results, to make sure the array keys are lined. We have a lot of consumers of these APIs and all I found did [0] instead of array_shift or something similar. So @rullzer and I think fixing the indexes here is the better idea.
@icewind1991 any other idea?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with UserMountCache.php around line 297 and Folder.php around line 326, then inspect the first-mount-point and first-node consumers in RetentionJob.php around lines 163 and 172. Trace the array_filter results and identify the returned APIs that rely on key 0. Done means affected returned arrays have sequential keys so existing consumers cannot encounter an undefined [0].
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100