From d1b982a335b71eba6f396a221e875a3a5562615f Mon Sep 17 00:00:00 2001 From: Mehrdad Esmaeilpour Date: Sun, 1 Nov 2020 10:10:46 +0330 Subject: [PATCH] :bug: Fix url escaping database name --- couchdb-exporter_test.go | 8 ++++---- lib/couchdb-client.go | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/couchdb-exporter_test.go b/couchdb-exporter_test.go index 2c208c4c..1436c650 100644 --- a/couchdb-exporter_test.go +++ b/couchdb-exporter_test.go @@ -200,7 +200,7 @@ func TestCouchdbStatsV1Integration(t *testing.T) { client := lib.NewCouchdbClient(dbUrl, basicAuth, true) databases := []string{"v1_testdb1", "v1_test/db2"} for _, db := range databases { - _, err = client.Request("PUT", fmt.Sprintf("%s/%s", client.BaseUri, url.PathEscape(db)), nil) + _, err = client.Request("PUT", fmt.Sprintf("%s/%s", client.BaseUri, url.QueryEscape(db)), nil) if err != nil { t.Error(err) } @@ -257,7 +257,7 @@ func TestCouchdbStatsV1Integration(t *testing.T) { }) for _, db := range databases { - _, err = client.Request("DELETE", fmt.Sprintf("%s/%s", client.BaseUri, url.PathEscape(db)), nil) + _, err = client.Request("DELETE", fmt.Sprintf("%s/%s", client.BaseUri, url.QueryEscape(db)), nil) if err != nil { t.Error(err) } @@ -310,7 +310,7 @@ func TestCouchdbStatsV2Integration(t *testing.T) { client := lib.NewCouchdbClient(dbUrl, basicAuth, true) databases := []string{"v2_testdb1", "v2_test/db2"} for _, db := range databases { - _, err = client.Request("PUT", fmt.Sprintf("%s/%s", client.BaseUri, url.PathEscape(db)), nil) + _, err = client.Request("PUT", fmt.Sprintf("%s/%s", client.BaseUri, url.QueryEscape(db)), nil) if err != nil { t.Error(err) } @@ -367,7 +367,7 @@ func TestCouchdbStatsV2Integration(t *testing.T) { }) for _, db := range databases { - _, err = client.Request("DELETE", fmt.Sprintf("%s/%s", client.BaseUri, url.PathEscape(db)), nil) + _, err = client.Request("DELETE", fmt.Sprintf("%s/%s", client.BaseUri, url.QueryEscape(db)), nil) if err != nil { t.Error(err) } diff --git a/lib/couchdb-client.go b/lib/couchdb-client.go index 6aad4c21..d66b7035 100644 --- a/lib/couchdb-client.go +++ b/lib/couchdb-client.go @@ -277,7 +277,7 @@ func (c *CouchdbClient) getDatabasesStatsByDbName(databases []string, concurrenc // scatter for _, dbName := range databases { dbName := dbName // rebind for closure to capture the value - escapedDbName := url.PathEscape(dbName) + escapedDbName := url.QueryEscape(dbName) go func() { err := semaphore.Acquire() if err != nil { @@ -329,7 +329,7 @@ type viewStats struct { } func (c *CouchdbClient) viewStats(isCouchdbV1 bool, dbName string, designDocId string, viewName string) viewStats { - escapedDbName := url.PathEscape(dbName) + escapedDbName := url.QueryEscape(dbName) query := strings.Join([]string{ "stale=ok", @@ -397,7 +397,7 @@ func (c *CouchdbClient) enhanceWithViewUpdateSeq(isCouchdbV1 bool, dbStatsByDbNa for dbName, dbStats := range dbStatsByDbName { dbName := dbName // rebind for closure to capture the value dbStats := dbStats // rebind for closure to capture the value - escapedDbName := url.PathEscape(dbName) + escapedDbName := url.QueryEscape(dbName) go func() { err := semaphore.Acquire() if err != nil {