Conversation
Handles access to Collections properties more defensive as they are optional according Protocol (..stated the internet... ;) )
There was a problem hiding this comment.
Pull request overview
This PR adds defensive checks for optional properties in the $collection array when accessing bodyprefs and mimesupport fields. The changes prevent potential undefined index errors by using !empty() checks with appropriate default values.
Changes:
- Added
!empty()checks forbodyprefsandmimesupportcollection properties across calendar, contacts, tasks, notes, and mail export functions - Standardized
truncationhandling for tasks and notes to match the pattern used in calendar and contacts - Updated error logging to include the same defensive checks for consistency
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@amulet1 : can you review this PR? Does it make sense? |
|
I am not a fan of This can potentially cause serious issues (maybe not in this particular case though). I think the idea here is to suppress warnings if some of the parameters were not defined by replacing them with default values. If so, I think (1) The difference is that (1) would convert '0' (or 0 or empty string) to empty array. In general case this is probably undesired. (2) would leave them intact and only use empty array for undefined values or null values, which looks more reasonable. There is an even cleaner way. Use null coalescing operator and it becomes this: I think (3) is what we should use going forward as a preferred way to fix potential issues with undefined variables. |
|
@amulet1 thanks for the review, adapted it accordingly. To be tested later and then I'll merge |
|
I am also wondering if maybe these defensive checks should also be done at the destination (i.e. in the corresponding Api.php files) as there could be other callers of API functions. |
|
@amulet1 I think you are right, my appròach was the cheap one to get rid of the warnings. The final approach would be to stabilize the EAS16.0 procotol implementation , but it requires deeper knowledge of the protocol and the current implementation. That is your recommendation? Should we abandon this changes torwards a deeper solution? |
I think these are good changes and they should be merged. Even if this is not a complete fix, at the very least it reduces errors/warnings in the logs.
Yes, but I am also limited on available time to devote to Horde. Currently I am mostly focused on obvious bug-fixes, reviving CI with unit tests and stability improvements (same as you are, I suppose). If we get a full control over the repository (and related things) we could reevaluate priorities and focus on supporting new things (such as modernizing javascript libraries, EAS, modern PHP standards, etc.). |
Handles access to Collections properties more defensive as they are optional according Protocol (..stated the internet... ;) )