Skip to content

Commit c7ee0dd

Browse files
authored
bindinfo: fix the bind fields with quotes or slashes (#11671) (#11726)
1 parent ae8d2f2 commit c7ee0dd

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

bindinfo/bind_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ func (s *testSuite) TestBindParse(c *C) {
134134
c.Check(bindData.Collation, Equals, "utf8mb4_bin")
135135
c.Check(bindData.CreateTime, NotNil)
136136
c.Check(bindData.UpdateTime, NotNil)
137+
138+
// Test fields with quotes or slashes.
139+
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"`
140+
tk.MustExec(sql)
141+
tk.MustExec(`DROP global binding for select * from t use index(idx) where a BETWEEN "a\nb\rc\td\0e" and "x"`)
137142
}
138143

139144
func (s *testSuite) TestGlobalBinding(c *C) {

bindinfo/handle.go

-13
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
package bindinfo
1515

1616
import (
17-
"bytes"
1817
"context"
1918
"fmt"
2019
"go.uber.org/zap"
@@ -188,7 +187,6 @@ func (h *BindHandle) AddBindRecord(record *BindRecord) (err error) {
188187
}
189188
record.UpdateTime = record.CreateTime
190189
record.Status = Using
191-
record.BindSQL = h.getEscapeCharacter(record.BindSQL)
192190

193191
// insert the BindRecord to the storage.
194192
_, err = exec.Execute(context.TODO(), h.insertBindInfoSQL(record))
@@ -446,14 +444,3 @@ func (h *BindHandle) logicalDeleteBindInfoSQL(normdOrigSQL, db string, updateTs
446444
normdOrigSQL,
447445
db)
448446
}
449-
450-
func (h *BindHandle) getEscapeCharacter(str string) string {
451-
var buffer bytes.Buffer
452-
for _, v := range str {
453-
if v == '\'' || v == '"' || v == '\\' {
454-
buffer.WriteString("\\")
455-
}
456-
buffer.WriteString(string(v))
457-
}
458-
return buffer.String()
459-
}

0 commit comments

Comments
 (0)