Allow RPC identifiers in E notation (#80)

This commit is contained in:
Calvin McAnarney 2016-08-08 05:47:07 +02:00 committed by Dave Collins
parent 64922553b5
commit 5f19113422

View file

@ -15,6 +15,7 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"math"
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
@ -266,7 +267,7 @@ type (
// the embedded ID (from the response) is nil. Otherwise, it is a // the embedded ID (from the response) is nil. Otherwise, it is a
// response. // response.
inMessage struct { inMessage struct {
ID *uint64 `json:"id"` ID *float64 `json:"id"`
*rawNotification *rawNotification
*rawResponse *rawResponse
} }
@ -337,12 +338,18 @@ func (c *Client) handleMessage(msg []byte) {
return return
} }
// ensure that in.ID can be converted to an integer without loss of precision
if *in.ID < 0 || *in.ID != math.Trunc(*in.ID) {
log.Warn("Malformed response: invalid identifier")
return
}
if in.rawResponse == nil { if in.rawResponse == nil {
log.Warn("Malformed response: missing result and error") log.Warn("Malformed response: missing result and error")
return return
} }
id := *in.ID id := uint64(*in.ID)
log.Tracef("Received response for id %d (result %s)", id, in.Result) log.Tracef("Received response for id %d (result %s)", id, in.Result)
request := c.removeRequest(id) request := c.removeRequest(id)