Merge PR #1260: Fixed url encoding issue

This commit is contained in:
Fabian 2018-06-15 13:24:04 -07:00 committed by Christopher Goes
parent e4685ecba5
commit f68e903d06
2 changed files with 9 additions and 2 deletions

View File

@ -321,8 +321,9 @@ func TestTxs(t *testing.T) {
assert.Equal(t, 1, len(indexedTxs))
// query sender
// also tests url decoding
addrBech := sdk.MustBech32ifyAcc(addr)
res, body = Request(t, port, "GET", fmt.Sprintf("/txs?tag=sender_bech32='%s'", addrBech), nil)
res, body = Request(t, port, "GET", "/txs?tag=sender_bech32=%27"+addrBech+"%27", nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)
err = cdc.UnmarshalJSON([]byte(body), &indexedTxs)

View File

@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net/http"
"net/url"
"strings"
"github.com/spf13/cobra"
@ -107,7 +108,12 @@ func SearchTxRequestHandlerFn(ctx context.CoreContext, cdc *wire.Codec) http.Han
}
keyValue := strings.Split(tag, "=")
key := keyValue[0]
value := keyValue[1]
value, err := url.QueryUnescape(keyValue[1])
if err != nil {
w.WriteHeader(400)
w.Write([]byte("Could not decode address: " + err.Error()))
return
}
if strings.HasSuffix(key, "_bech32") {
bech32address := strings.Trim(value, "'")
prefix := strings.Split(bech32address, "1")[0]