Skip to content

Fix MergeAPIExtensionsJSON panic on nil Raw bytes#110

Merged
harveyxia merged 1 commit intoreddit:mainfrom
ckw4ng:fix-merge-nil-raw-json
Apr 20, 2026
Merged

Fix MergeAPIExtensionsJSON panic on nil Raw bytes#110
harveyxia merged 1 commit intoreddit:mainfrom
ckw4ng:fix-merge-nil-raw-json

Conversation

@ckw4ng
Copy link
Copy Markdown
Contributor

@ckw4ng ckw4ng commented Apr 17, 2026

💸 TL;DR

When MergeAPIExtensionsJSON is called with (nil, nil), it returns &apiextensionsv1.JSON{} with Raw: nil. If the result is then passed back into MergeAPIExtensionsJSON (as happens when callers merge in a loop over multiple inputs), the function attempts to json.Unmarshal nil bytes, causing "unexpected end of JSON input".

Add len(Raw) > 0 guards before both json.Unmarshal calls so that non-nil structs with nil or empty Raw are treated the same as nil pointers. The nil+nil early return is preserved to avoid changing the serialized form of existing callers' outputs.

🧪 Testing Steps / Validation

Unit tests.

✅ Checks

  • CI tests (if present) are passing
  • Adheres to code style for repo
  • Contributor License Agreement (CLA) completed if not a Reddit employee

When MergeAPIExtensionsJSON is called with (nil, nil), it returns
&apiextensionsv1.JSON{} with Raw: nil. If the result is then passed
back into MergeAPIExtensionsJSON (as happens when callers merge in a
loop over multiple inputs), the function attempts to json.Unmarshal
nil bytes, causing "unexpected end of JSON input".

Add len(Raw) > 0 guards before both json.Unmarshal calls so that
non-nil structs with nil or empty Raw are treated the same as nil
pointers. The nil+nil early return is preserved to avoid changing
the serialized form of existing callers' outputs.
@ckw4ng ckw4ng marked this pull request as ready for review April 17, 2026 22:35
@ckw4ng ckw4ng requested a review from a team as a code owner April 17, 2026 22:35
@ckw4ng ckw4ng requested a review from harveyxia April 17, 2026 22:35
@harveyxia harveyxia merged commit e6216b4 into reddit:main Apr 20, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants