Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Defined2014 committed Nov 14, 2023
1 parent 950f505 commit b47189d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
19 changes: 18 additions & 1 deletion src/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main
import (
"database/sql"
"regexp"
"strings"
"time"

"github.com/pingcap/errors"
Expand Down Expand Up @@ -51,6 +52,22 @@ func OpenDBWithRetry(driverName, dataSourceName string, retryCount int) (mdb *sq
return
}

func processEscapes(str string) string {
escapeMap := map[string]string{
`\n`: "\n",
`\t`: "\t",
`\r`: "\r",
`\\`: "\\",
`\/`: "/",
}

for escape, replacement := range escapeMap {
str = strings.ReplaceAll(str, escape, replacement)
}

return str
}

func ParseReplaceRegex(originalString string) ([]*ReplaceRegex, error) {
var begin, middle, end, cnt int
ret := make([]*ReplaceRegex, 0)
Expand All @@ -75,7 +92,7 @@ func ParseReplaceRegex(originalString string) ([]*ReplaceRegex, error) {
}
ret = append(ret, &ReplaceRegex{
regex: reg,
replace: originalString[middle+1 : end],
replace: processEscapes(originalString[middle+1 : end]),
})
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,12 @@ func TestParseReplaceRegex(t *testing.T) {
input: "Some infos [conn=xxx]",
output: "Some infos [conn=xxx]",
},
/* TODO: support replaced with '\t', '\n', '\/' etc
{
succ: true,
regexpStr: `/a/\/b/`,
regexpStr: `/a/\/b\r\t/`,
input: "a",
output: "/b",
output: "/b\r\t",
},
*/
{
succ: false,
regexpStr: `/conn=[0-9]+/conn=<num>`,
Expand Down

0 comments on commit b47189d

Please sign in to comment.