Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bindinfo: fix the bind fields with quotes or slashes (#11671) #11726

Merged
merged 2 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bindinfo/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ func (s *testSuite) TestBindParse(c *C) {
c.Check(bindData.Collation, Equals, "utf8mb4_bin")
c.Check(bindData.CreateTime, NotNil)
c.Check(bindData.UpdateTime, NotNil)

// Test fields with quotes or slashes.
sql = `CREATE GLOBAL BINDING FOR select * from t where a BETWEEN "a" and "b" USING select * from t use index(idx) where a BETWEEN "a\nb\rc\td\0e" and "x"`
tk.MustExec(sql)
tk.MustExec(`DROP global binding for select * from t use index(idx) where a BETWEEN "a\nb\rc\td\0e" and "x"`)
}

func (s *testSuite) TestGlobalBinding(c *C) {
Expand Down
13 changes: 0 additions & 13 deletions bindinfo/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package bindinfo

import (
"bytes"
"context"
"fmt"
"go.uber.org/zap"
Expand Down Expand Up @@ -188,7 +187,6 @@ func (h *BindHandle) AddBindRecord(record *BindRecord) (err error) {
}
record.UpdateTime = record.CreateTime
record.Status = Using
record.BindSQL = h.getEscapeCharacter(record.BindSQL)

// insert the BindRecord to the storage.
_, err = exec.Execute(context.TODO(), h.insertBindInfoSQL(record))
Expand Down Expand Up @@ -446,14 +444,3 @@ func (h *BindHandle) logicalDeleteBindInfoSQL(normdOrigSQL, db string, updateTs
normdOrigSQL,
db)
}

func (h *BindHandle) getEscapeCharacter(str string) string {
var buffer bytes.Buffer
for _, v := range str {
if v == '\'' || v == '"' || v == '\\' {
buffer.WriteString("\\")
}
buffer.WriteString(string(v))
}
return buffer.String()
}