From 9c380dd67bedca75b7a1d2f7e3c0bbecd492799f Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Mon, 10 Oct 2022 11:37:49 +0800 Subject: [PATCH] br: handle special character in SQL (#37486) (#37639) 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 90f72d0778407..20e441f86aecf 100644 --- a/br/pkg/storage/parse_test.go +++ b/br/pkg/storage/parse_test.go @@ -194,3 +194,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 1e14d970acbb0..9eeb4e48cbdd5 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