From 5d35dec91180ffc408645616cbe558af033d9512 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Wed, 15 Nov 2023 18:14:40 +0800 Subject: [PATCH] Fix URL query escape for RegionStatsByStartEndKey Signed-off-by: JmPotato --- client/http/api.go | 12 +++++++++--- client/http/client.go | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/client/http/api.go b/client/http/api.go index 906748dec3a2..e6f1925900cc 100644 --- a/client/http/api.go +++ b/client/http/api.go @@ -79,7 +79,10 @@ func RegionByKey(key []byte) string { // RegionsByKey returns the path of PD HTTP API to scan regions with given start key, end key and limit parameters. func RegionsByKey(startKey, endKey []byte, limit int) string { return fmt.Sprintf("%s?start_key=%s&end_key=%s&limit=%d", - regionsByKey, url.QueryEscape(string(startKey)), url.QueryEscape(string(endKey)), limit) + regionsByKey, + url.QueryEscape(string(startKey)), + url.QueryEscape(string(endKey)), + limit) } // RegionsByStoreID returns the path of PD HTTP API to get regions by store ID. @@ -88,8 +91,11 @@ func RegionsByStoreID(storeID uint64) string { } // RegionStatsByStartEndKey returns the path of PD HTTP API to get region stats by start key and end key. -func RegionStatsByStartEndKey(startKey, endKey string) string { - return fmt.Sprintf("%s?start_key=%s&end_key=%s", StatsRegion, startKey, endKey) +func RegionStatsByStartEndKey(startKey, endKey []byte) string { + return fmt.Sprintf("%s?start_key=%s&end_key=%s", + StatsRegion, + url.QueryEscape(string(startKey)), + url.QueryEscape(string(endKey))) } // StoreByID returns the store API with store ID parameter. diff --git a/client/http/client.go b/client/http/client.go index efd23bf623f1..673e2dbde6d0 100644 --- a/client/http/client.go +++ b/client/http/client.go @@ -305,7 +305,7 @@ func (c *client) GetRegionStatusByKey(ctx context.Context, startKey, endKey []by var regionStats RegionStats err := c.requestWithRetry( ctx, "GetRegionStatusByKey", - RegionStatsByStartEndKey(string(startKey), string(endKey)), http.MethodGet, + RegionStatsByStartEndKey(startKey, endKey), http.MethodGet, ®ionStats, ) if err != nil {