diff --git a/region/info.go b/region/info.go index 4000e559..b9f48f43 100644 --- a/region/info.go +++ b/region/info.go @@ -12,6 +12,7 @@ import ( "encoding/binary" "encoding/json" "fmt" + "strconv" "sync" "github.com/tsuna/gohbase/hrpc" @@ -358,11 +359,14 @@ func findCommaFromEnd(b []byte, offset int) int { func (i *info) MarshalJSON() ([]byte, error) { - var ctxError string + var ctxError, client string if i.ctx != nil { ctxError = fmt.Sprint(i.ctx.Err()) } + if i.Client() != nil { + client = i.Client().String() + } state := struct { Id uint64 @@ -373,18 +377,20 @@ func (i *info) MarshalJSON() ([]byte, error) { StopKey string ContextInstance string Err string + ClientPtr string Client string Available bool }{ Id: i.id, - Namespace: string(i.namespace), - Table: string(i.table), - Name: string(i.name), - StartKey: string(i.startKey), - StopKey: string(i.stopKey), + Namespace: strconv.QuoteToASCII(string(i.namespace)), + Table: strconv.QuoteToASCII(string(i.table)), + Name: strconv.QuoteToASCII(string(i.name)), + StartKey: strconv.QuoteToASCII(string(i.startKey)), + StopKey: strconv.QuoteToASCII(string(i.stopKey)), ContextInstance: fmt.Sprintf("%p", (i.ctx)), Err: ctxError, - Client: fmt.Sprintf("%p", (i.Client())), + ClientPtr: fmt.Sprintf("%p", (i.Client())), + Client: client, Available: !i.IsUnavailable(), } jsonVal, err := json.Marshal(state) diff --git a/region/info_test.go b/region/info_test.go index d59b091a..a7bc2552 100644 --- a/region/info_test.go +++ b/region/info_test.go @@ -9,6 +9,7 @@ import ( "bytes" "context" "encoding/json" + "strconv" "strings" "testing" "time" @@ -213,12 +214,12 @@ func TestRegionInfoMarshalJson(t *testing.T) { } assert.Equal(t, float64(id), jsonUnMarshal["Id"]) - assert.Equal(t, string(table), jsonUnMarshal["Table"]) - assert.Equal(t, string(name), jsonUnMarshal["Name"]) - assert.Equal(t, string(startKey), jsonUnMarshal["StartKey"]) - assert.Equal(t, string(stopKey), jsonUnMarshal["StopKey"]) + assert.Equal(t, strconv.QuoteToASCII(string(table)), jsonUnMarshal["Table"]) + assert.Equal(t, strconv.QuoteToASCII(string(name)), jsonUnMarshal["Name"]) + assert.Equal(t, strconv.QuoteToASCII(string(startKey)), jsonUnMarshal["StartKey"]) + assert.Equal(t, strconv.QuoteToASCII(string(stopKey)), jsonUnMarshal["StopKey"]) assert.Equal(t, true, jsonUnMarshal["Available"]) - assert.Equal(t, string(namespace), jsonUnMarshal["Namespace"]) + assert.Equal(t, strconv.QuoteToASCII(string(namespace)), jsonUnMarshal["Namespace"]) }