Skip to content

fix: reindex array after array_diff to prevent malformed output (#11741)#11780

Open
aakarsh12x wants to merge 5 commits intoappwrite:1.9.xfrom
aakarsh12x:fix/11741-array-diff-reindex
Open

fix: reindex array after array_diff to prevent malformed output (#11741)#11780
aakarsh12x wants to merge 5 commits intoappwrite:1.9.xfrom
aakarsh12x:fix/11741-array-diff-reindex

Conversation

@aakarsh12x
Copy link
Copy Markdown

Summary

This fixes an issue in the GitHub pull request cleanup flow where �rray_diff() was used without reindexing the result before storing it back on the repository document.

Root Cause

�rray_diff() preserves the original numeric keys. After removing a pull request ID from providerPullRequestIds, the resulting array could contain gaps in its indexes.

When that sparse array was stored, it could be serialized as an object-like structure instead of a proper JSON array, which can break downstream code expecting a sequential list.

Fix

Wrap the existing �rray_diff() call with �rray_values() in src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php so providerPullRequestIds is always reindexed before it is written back.

Why This Change Is Minimal

This keeps the patch intentionally small and follows the existing pattern already used elsewhere in the codebase for �rray_diff() results that are persisted or returned.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 4, 2026

Greptile Summary

This PR fixes a subtle but real PHP serialization bug in the GitHub pull request cleanup flow: array_diff() preserves original numeric keys, so after removing a PR ID from providerPullRequestIds, the resulting sparse array could be serialized as a JSON object (e.g. {"1": 456}) rather than a JSON array ([456]). Wrapping the call with array_values() ensures the array is always re-indexed before being written back to the database.

  • Fix location: src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php line 237 — array_diff() is now wrapped with array_values() before the result is persisted.
  • The change is intentionally minimal and matches the pattern already used elsewhere in the codebase for array_diff() results that are stored or returned.
  • No new dependencies, no behavior changes beyond the reindexing, and the fix is confined to the "closed" PR action branch.

Confidence Score: 5/5

Safe to merge — the fix is correct, minimal, and addresses a real data-integrity issue without introducing new risk.

Single, well-understood one-line change that wraps array_diff() with array_values(). No P0/P1 issues found. The fix correctly prevents sparse arrays from being serialized as JSON objects when stored in the database.

No files require special attention.

Vulnerabilities

No security concerns identified.

Important Files Changed

Filename Overview
src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php Single-line fix: wraps array_diff() with array_values() to reindex providerPullRequestIds before persisting, preventing sparse-array / JSON-object serialization issues. Change is correct and safe.

Reviews (5): Last reviewed commit: "Merge branch 'appwrite:1.9.x' into fix/1..." | Re-trigger Greptile

@aakarsh12x
Copy link
Copy Markdown
Author

@ChiragAgg5k could you please review this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant