Honor explicit nulls in imap config during vendor merge #511
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Treat explicit null values in the application config as overrides when merging the package (vendor) config into the application's
imapconfig.Problem
When users set keys to
nullin their publishedconfig/imap.php(for example'flags' => nullto accept all flags), the package's custom merge routine could either:nulloverride and keep vendor defaults, orThis happens because the provider merges the vendor config and the app config with a custom
array_merge_recursive_distinct()implementation which does not treatnullas an explicit replacement and may attempt to operate onnullvalues as if they were arrays.Cause
LaravelServiceProvider::setVendorConfig()uses the vendor config as the base and merges the application config into it usingarray_merge_recursive_distinct($vendor_config, $config). If the application config contains keys explicitly set tonull, the merge routine can mis-handle those values and produce invalid numeric keys or fail with undefined index errors.Change
Before performing the merge, detect keys in the application config that are explicitly set to
nulland set the corresponding keys in$vendor_configtonull. This makesnullan explicit override and prevents the merge routine from encountering invalid states.Concretely:
=== null, setvendor_config[key] = null.Benefits
'flags' => nullinconfig/imap.phpwill be respected (e.g. "accept all given flags").null.Verification / Test steps
config/imap.php.'flags' => nullinconfig/imap.php.php artisan config:clearconfig('imap.flags')returnsnull.Compatibility & Risk
imapconfig are unaffected.Follow-up
Consider hardening
array_merge_recursive_distinct()in a later PR to generally handle non-array and null values more robustly across nested merges. This PR is intentionally minimal to fix the immediate incorrect behavior while remaining easy to review.