Skip to content

Commit

Permalink
util: Reduce boundery check in escape functions. (#1316)
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed Mar 11, 2022
1 parent c1aa681 commit ce134bf
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions utils.go
Expand Up @@ -652,32 +652,32 @@ func escapeBytesBackslash(buf, v []byte) []byte {
for _, c := range v {
switch c {
case '\x00':
buf[pos] = '\\'
buf[pos+1] = '0'
buf[pos] = '\\'
pos += 2
case '\n':
buf[pos] = '\\'
buf[pos+1] = 'n'
buf[pos] = '\\'
pos += 2
case '\r':
buf[pos] = '\\'
buf[pos+1] = 'r'
buf[pos] = '\\'
pos += 2
case '\x1a':
buf[pos] = '\\'
buf[pos+1] = 'Z'
buf[pos] = '\\'
pos += 2
case '\'':
buf[pos] = '\\'
buf[pos+1] = '\''
buf[pos] = '\\'
pos += 2
case '"':
buf[pos] = '\\'
buf[pos+1] = '"'
buf[pos] = '\\'
pos += 2
case '\\':
buf[pos] = '\\'
buf[pos+1] = '\\'
buf[pos] = '\\'
pos += 2
default:
buf[pos] = c
Expand All @@ -697,32 +697,32 @@ func escapeStringBackslash(buf []byte, v string) []byte {
c := v[i]
switch c {
case '\x00':
buf[pos] = '\\'
buf[pos+1] = '0'
buf[pos] = '\\'
pos += 2
case '\n':
buf[pos] = '\\'
buf[pos+1] = 'n'
buf[pos] = '\\'
pos += 2
case '\r':
buf[pos] = '\\'
buf[pos+1] = 'r'
buf[pos] = '\\'
pos += 2
case '\x1a':
buf[pos] = '\\'
buf[pos+1] = 'Z'
buf[pos] = '\\'
pos += 2
case '\'':
buf[pos] = '\\'
buf[pos+1] = '\''
buf[pos] = '\\'
pos += 2
case '"':
buf[pos] = '\\'
buf[pos+1] = '"'
buf[pos] = '\\'
pos += 2
case '\\':
buf[pos] = '\\'
buf[pos+1] = '\\'
buf[pos] = '\\'
pos += 2
default:
buf[pos] = c
Expand All @@ -744,8 +744,8 @@ func escapeBytesQuotes(buf, v []byte) []byte {

for _, c := range v {
if c == '\'' {
buf[pos] = '\''
buf[pos+1] = '\''
buf[pos] = '\''
pos += 2
} else {
buf[pos] = c
Expand All @@ -764,8 +764,8 @@ func escapeStringQuotes(buf []byte, v string) []byte {
for i := 0; i < len(v); i++ {
c := v[i]
if c == '\'' {
buf[pos] = '\''
buf[pos+1] = '\''
buf[pos] = '\''
pos += 2
} else {
buf[pos] = c
Expand Down

0 comments on commit ce134bf

Please sign in to comment.