@@ -102,6 +102,39 @@ func newResponse(id any, result any, rerr error) jsonrpc2.Message {
102102 return msg
103103}
104104
105+ // go-sdk#976: empty method must decode as a request (encode omits empty method).
106+ func TestDecodeEmptyMethodRequest (t * testing.T ) {
107+ encoded := []byte (`{"jsonrpc":"2.0","id":5,"method":"","params":{}}` )
108+ msg , err := jsonrpc2 .DecodeMessage (encoded )
109+ if err != nil {
110+ t .Fatal (err )
111+ }
112+ req , ok := msg .(* jsonrpc2.Request )
113+ if ! ok {
114+ t .Fatalf ("message type = %T, want *jsonrpc2.Request" , msg )
115+ }
116+ if req .Method != "" {
117+ t .Errorf ("Method = %q, want empty string" , req .Method )
118+ }
119+ if req .ID != jsonrpc2 .Int64ID (5 ) {
120+ t .Errorf ("ID = %v, want 5" , req .ID .Raw ())
121+ }
122+ if ! req .IsCall () {
123+ t .Error ("empty method with id=5 should be a call" )
124+ }
125+ }
126+
127+ func TestDecodeResponseUnchanged (t * testing.T ) {
128+ encoded := []byte (`{"jsonrpc":"2.0","id":2,"result":{}}` )
129+ msg , err := jsonrpc2 .DecodeMessage (encoded )
130+ if err != nil {
131+ t .Fatal (err )
132+ }
133+ if _ , ok := msg .(* jsonrpc2.Response ); ! ok {
134+ t .Fatalf ("message type = %T, want *jsonrpc2.Response" , msg )
135+ }
136+ }
137+
105138func checkJSON (t * testing.T , got , want []byte ) {
106139 // compare the compact form, to allow for formatting differences
107140 g := & bytes.Buffer {}
0 commit comments