Skip to content

Conversation

ankittk
Copy link

@ankittk ankittk commented Aug 7, 2025

fix: ensure JSON-RPC 2.0 compliance for nil slices and maps

The Params() function was returning null for nil slices and nil maps,
which violates the JSON-RPC 2.0 specification that requires params
to be either an array or an object.

  • Fix nil slice handling: convert to empty array [] instead of null
  • Fix nil map handling: convert to empty object {} instead of null
  • Added tests for nil slice/map scenarios
  • Maintain backward compatibility for all existing functionality

Before

var nilSlice []int = nil
result := Params(nilSlice)
// Returns: null (invalid JSON-RPC)

var nilMap map[string]interface{} = nil  
result := Params(nilMap)
// Returns: null (invalid JSON-RPC)

After

var nilSlice []int = nil
result := Params(nilSlice)
// Returns: [] (empty array - valid JSON-RPC)

var nilMap map[string]interface{} = nil
result := Params(nilMap)  
// Returns: {} (empty object - valid JSON-RPC)

@ankittk ankittk changed the title fix: jsonrpc nil bug fix: nil slices and maps in params Aug 7, 2025
@ankittk
Copy link
Author

ankittk commented Aug 19, 2025

@ybbus How to get this reviewed?

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