Skip to content

Commit

Permalink
Merge pull request #1053 from Juneezee/refactor/strings-replaceall
Browse files Browse the repository at this point in the history
refactor: replace strings.Replace with strings.ReplaceAll
  • Loading branch information
mileszhang2016 authored Jun 7, 2022
2 parents a1d91ef + 9ad187e commit dc1d502
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bfe_basic/action/action_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func ReqQueryRename(req *bfe_basic.Request, oldName string, newName string) {
// rename keys
srcKey := "&" + oldName + "="
dstKey := "&" + newName + "="
rawQuery = strings.Replace(rawQuery, srcKey, dstKey, -1)
rawQuery = strings.ReplaceAll(rawQuery, srcKey, dstKey)

// remove prefix "&"
req.HttpRequest.URL.RawQuery = rawQuery[1:]
Expand Down
2 changes: 1 addition & 1 deletion bfe_basic/condition/primitive.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ func parserHashSectionConf(section string) (int, int, error) {
// checkt numbers
var start, end int
for i, numberRawStr := range numbers {
numberStr := strings.Replace(numberRawStr, " ", "", -1)
numberStr := strings.ReplaceAll(numberRawStr, " ", "")
number, err := strconv.Atoi(numberStr)
if err != nil {
return 0, 0, fmt.Errorf("hash value check section %s number %s err %s",
Expand Down
2 changes: 1 addition & 1 deletion bfe_fcgi/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func buildMetaValsAndMethod(r *http.Request, root string, envVars map[string]str

// https://tools.ietf.org/html/rfc3875#section-4.1.18
for key, val := range r.Header {
header := strings.Replace(strings.ToUpper(key), "-", "_", -1)
header := strings.ReplaceAll(strings.ToUpper(key), "-", "_")
metaHeader.Add("HTTP_"+header, strings.Join(val, ", "))
}

Expand Down
4 changes: 2 additions & 2 deletions bfe_http/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func testMissingFile(t *testing.T, req *Request) {
}

func newTestMultipartRequest(t *testing.T) *Request {
b := bytes.NewBufferString(strings.Replace(message, "\n", "\r\n", -1))
b := bytes.NewBufferString(strings.ReplaceAll(message, "\n", "\r\n"))
req, err := NewRequest(MethodPost, "/", b)
if err != nil {
t.Fatal("NewRequest:", err)
Expand Down Expand Up @@ -498,7 +498,7 @@ Content-Disposition: form-data; name="textb"

func benchmarkReadRequest(b *testing.B, request string) {
request += "\n" // final \n
request = strings.Replace(request, "\n", "\r\n", -1) // expand \n to \r\n
request = strings.ReplaceAll(request, "\n", "\r\n") // expand \n to \r\n
b.SetBytes(int64(len(request)))
r := bfe_bufio.NewReader(&infiniteReader{buf: []byte(request)})
b.ReportAllocs()
Expand Down
2 changes: 1 addition & 1 deletion bfe_http2/hpack/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,5 @@ func TestEncoderSetMaxDynamicTableSizeLimit(t *testing.T) {
}

func removeSpace(s string) string {
return strings.Replace(s, " ", "", -1)
return strings.ReplaceAll(s, " ", "")
}
8 changes: 4 additions & 4 deletions bfe_http2/hpack/hpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ func TestHuffmanDecode(t *testing.T) {
}
for i, tt := range tests {
var buf bytes.Buffer
in, err := hex.DecodeString(strings.Replace(tt.inHex, " ", "", -1))
in, err := hex.DecodeString(strings.ReplaceAll(tt.inHex, " ", ""))
if err != nil {
t.Errorf("%d. hex input error: %v", i, err)
continue
Expand Down Expand Up @@ -589,7 +589,7 @@ func TestAppendHuffmanString(t *testing.T) {
}
for i, tt := range tests {
buf := []byte{}
want := strings.Replace(tt.want, " ", "", -1)
want := strings.ReplaceAll(tt.want, " ", "")
buf = AppendHuffmanString(buf, tt.in)
if got := hex.EncodeToString(buf); want != got {
t.Errorf("%d. encode = %q; want %q", i, got, want)
Expand Down Expand Up @@ -758,8 +758,8 @@ func TestHuffmanFuzzCrash(t *testing.T) {
}

func dehex(s string) []byte {
s = strings.Replace(s, " ", "", -1)
s = strings.Replace(s, "\n", "", -1)
s = strings.ReplaceAll(s, " ", "")
s = strings.ReplaceAll(s, "\n", "")
b, err := hex.DecodeString(s)
if err != nil {
panic(err)
Expand Down
8 changes: 4 additions & 4 deletions bfe_net/textproto/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func TestCommonHeaders(t *testing.T) {
}
}

var clientHeaders = strings.Replace(`Host: golang.org
var clientHeaders = strings.ReplaceAll(`Host: golang.org
Connection: keep-alive
Cache-Control: max-age=0
Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Expand All @@ -299,9 +299,9 @@ Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
COOKIE: __utma=000000000.0000000000.0000000000.0000000000.0000000000.00; __utmb=000000000.0.00.0000000000; __utmc=000000000; __utmz=000000000.0000000000.00.0.utmcsr=code.google.com|utmccn=(referral)|utmcmd=referral|utmcct=/p/go/issues/detail
Non-Interned: test
`, "\n", "\r\n", -1)
`, "\n", "\r\n")

var serverHeaders = strings.Replace(`Content-Type: text/html; charset=utf-8
var serverHeaders = strings.ReplaceAll(`Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Date: Thu, 27 Sep 2012 09:03:33 GMT
Server: Google Frontend
Expand All @@ -311,7 +311,7 @@ VIA: 1.1 proxy.example.com:80 (XXX/n.n.n-nnn)
Connection: Close
Non-Interned: test
`, "\n", "\r\n", -1)
`, "\n", "\r\n")

func BenchmarkReadMIMEHeader(b *testing.B) {
b.ReportAllocs()
Expand Down

0 comments on commit dc1d502

Please sign in to comment.