From 5f1911342274c2e2dc25d10f249f890f47a31ac3 Mon Sep 17 00:00:00 2001 From: Calvin McAnarney Date: Mon, 8 Aug 2016 05:47:07 +0200 Subject: [PATCH] Allow RPC identifiers in E notation (#80) --- infrastructure.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/infrastructure.go b/infrastructure.go index 098edcc5..985441c9 100644 --- a/infrastructure.go +++ b/infrastructure.go @@ -15,6 +15,7 @@ import ( "fmt" "io" "io/ioutil" + "math" "net" "net/http" "net/url" @@ -266,7 +267,7 @@ type ( // the embedded ID (from the response) is nil. Otherwise, it is a // response. inMessage struct { - ID *uint64 `json:"id"` + ID *float64 `json:"id"` *rawNotification *rawResponse } @@ -337,12 +338,18 @@ func (c *Client) handleMessage(msg []byte) { 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 { log.Warn("Malformed response: missing result and error") return } - id := *in.ID + id := uint64(*in.ID) log.Tracef("Received response for id %d (result %s)", id, in.Result) request := c.removeRequest(id)