From aab394fb420afabd486c0075deda1167b6c48063 Mon Sep 17 00:00:00 2001 From: MoCuishle28 <32541204+MoCuishle28@users.noreply.github.com> Date: Tue, 6 Sep 2022 15:04:56 +0800 Subject: [PATCH] br: handle special character in SQL (#37486) close pingcap/tidb#37469 --- br/pkg/storage/parse_test.go | 46 ++++++++++++++++++++++++++++++++++++ executor/brie.go | 3 +-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/br/pkg/storage/parse_test.go b/br/pkg/storage/parse_test.go index 2de924d27e946..b9a5d75d29322 100644 --- a/br/pkg/storage/parse_test.go +++ b/br/pkg/storage/parse_test.go @@ -213,3 +213,49 @@ func TestFormatBackendURL(t *testing.T) { }) require.Equal(t, "azure://bucket/some%20prefix/", backendURL.String()) } + +func TestParseRawURL(t *testing.T) { + cases := []struct { + url string + schema string + host string + path string + accessKey string + secretAccessKey string + }{ + { + url: `s3://bucket/prefix/path?access-key=NXN7IPIOSAAKDEEOLMAF&secret-access-key=nREY/7DtPaIbYKrKlEEMMF/ExCiJEX=XMLPUANw`, + schema: "s3", + host: "bucket", + path: "/prefix/path", + accessKey: "NXN7IPIOSAAKDEEOLMAF", // fake ak/sk + secretAccessKey: "nREY/7DtPaIbYKrKlEEMMF/ExCiJEX=XMLPUANw", // w/o "+" + }, + { + url: `s3://bucket/prefix/path?access-key=NXN7IPIOSAAKDEEOLMAF&secret-access-key=nREY/7Dt+PaIbYKrKlEEMMF/ExCiJEX=XMLPUANw`, + schema: "s3", + host: "bucket", + path: "/prefix/path", + accessKey: "NXN7IPIOSAAKDEEOLMAF", // fake ak/sk + secretAccessKey: "nREY/7Dt+PaIbYKrKlEEMMF/ExCiJEX=XMLPUANw", // with "+" + }, + } + + for _, c := range cases { + storageRawURL := c.url + storageURL, err := ParseRawURL(storageRawURL) + require.NoError(t, err) + + require.Equal(t, c.schema, storageURL.Scheme) + require.Equal(t, c.host, storageURL.Host) + require.Equal(t, c.path, storageURL.Path) + + require.Equal(t, 1, len(storageURL.Query()["access-key"])) + accessKey := storageURL.Query()["access-key"][0] + require.Equal(t, c.accessKey, accessKey) + + require.Equal(t, 1, len(storageURL.Query()["secret-access-key"])) + secretAccessKey := storageURL.Query()["secret-access-key"][0] + require.Equal(t, c.secretAccessKey, secretAccessKey) + } +} diff --git a/executor/brie.go b/executor/brie.go index f77f1567f7b64..96cb1ec7c26fb 100644 --- a/executor/brie.go +++ b/executor/brie.go @@ -17,7 +17,6 @@ package executor import ( "bytes" "context" - "net/url" "strings" "sync" "sync/atomic" @@ -225,7 +224,7 @@ func (b *executorBuilder) buildBRIE(s *ast.BRIEStmt, schema *expression.Schema) }, } - storageURL, err := url.Parse(s.Storage) + storageURL, err := storage.ParseRawURL(s.Storage) if err != nil { b.err = errors.Annotate(err, "invalid destination URL") return nil