Skip to content

Conversation

@ryanio
Copy link
Collaborator

@ryanio ryanio commented Jan 16, 2026

Summary

  • Fixed objectToSearchParams to correctly serialize falsy values (0, false, empty strings) that were incorrectly being filtered out by truthy checks
  • Uses the idiomatic != null pattern which checks for both null and undefined in one comparison
  • Added String() conversion for type safety when appending to URLSearchParams
  • Simplified the logic by checking Array.isArray() first (since arrays are always truthy)

This is a cleaner alternative to #1874 which uses the same fix but with more verbose explicit checks.

Changes

Before:

if (value && Array.isArray(value)) {
  value.forEach((item) => item && urlSearchParams.append(key, item));
} else if (value) {
  urlSearchParams.append(key, value);
}

After:

if (Array.isArray(value)) {
  value.forEach((item) => {
    if (item != null) {
      urlSearchParams.append(key, String(item));
    }
  });
} else if (value != null) {
  urlSearchParams.append(key, String(value));
}

Test plan

  • Added test for serializing 0 and false query params
  • Added test for serializing empty string query params
  • Added test for excluding null and undefined query params
  • Added test for arrays with falsy values (e.g., [0, 1, 2])
  • Added test for filtering null/undefined from array params
  • All existing tests pass

🤖 Generated with Claude Code

The objectToSearchParams method was using truthy checks which
incorrectly filtered out valid falsy values like 0, false, and
empty strings. Changed to explicit null/undefined checks using
the idiomatic != null pattern.

Also added String() conversion for type safety when appending
values to URLSearchParams.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ryanio ryanio merged commit bd70679 into main Jan 16, 2026
7 of 8 checks passed
@ryanio ryanio deleted the fix/query-param-serialization branch January 16, 2026 20:47
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.

2 participants