File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -495,6 +495,9 @@ func TestTablesTable(t *testing.T) {
495495 require .NoError (t , err )
496496 require .Equal (t , 2 , selectTables )
497497 require .Equal (t , totalTables , remainTables + selectTables )
498+
499+ tk .MustExec ("create table test.`$a$a` (a int)" )
500+ tk .MustQuery ("select count(*) from information_schema.tables where table_name like '$a$%'" ).Check (testkit .Rows ("1" ))
498501}
499502
500503func TestColumnTable (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ package stringutil
1717import (
1818 "bytes"
1919 "fmt"
20+ "regexp"
2021 "slices"
2122 "strings"
2223 "unicode/utf8"
@@ -259,18 +260,21 @@ func matchRune(a, b rune) bool {
259260// CompileLike2Regexp convert a like `lhs` to a regular expression
260261func CompileLike2Regexp (str string ) string {
261262 patChars , patTypes := CompilePattern (str , '\\' )
262- var result []rune
263+ var result strings.Builder
264+ result .Grow (len (patChars )* 2 + 2 )
265+ result .WriteByte ('^' )
263266 for i := range patChars {
264267 switch patTypes [i ] {
265268 case PatMatch :
266- result = append ( result , patChars [i ])
269+ result . WriteString ( regexp . QuoteMeta ( string ( patChars [i ])) )
267270 case PatOne :
268- result = append ( result , '.' )
271+ result . WriteByte ( '.' )
269272 case PatAny :
270- result = append ( result , '.' , '*' )
273+ result . WriteString ( ".*" )
271274 }
272275 }
273- return "^" + string (result ) + "$"
276+ result .WriteByte ('$' )
277+ return result .String ()
274278}
275279
276280// DoMatchBinary is an adapter for `DoMatchInner`, `str` is binary strings or ascii string.
Original file line number Diff line number Diff line change @@ -116,6 +116,9 @@ func TestCompileLike2Regexp(t *testing.T) {
116116 {`` , `^$` },
117117 {`a` , `^a$` },
118118 {`aA` , `^aA$` },
119+ {`$a$%` , `^\$a\$.*$` },
120+ {`a.b%` , `^a\.b.*$` },
121+ {`a+b` , `^a\+b$` },
119122 {`_` , `^.$` },
120123 {`__` , `^..$` },
121124 {`%` , `^.*$` },
@@ -124,7 +127,7 @@ func TestCompileLike2Regexp(t *testing.T) {
124127 {`a%` , `^a.*$` },
125128 {`\%a` , `^%a$` },
126129 {`\_a` , `^_a$` },
127- {`\\_a` , `^\.a$` },
130+ {`\\_a` , `^\\ .a$` },
128131 {`\a\b` , `^ab$` },
129132 {`%%_` , `^..*$` },
130133 {`%_%_aA` , "^...*aA$" },
You can’t perform that action at this time.
0 commit comments