mirror of https://github.com/gofiber/fiber.git
👋 remove unused fn
parent
ce897c0b66
commit
ee596c2c8d
31
helpers.go
31
helpers.go
|
@ -117,37 +117,6 @@ func removeNewLines(raw string) string {
|
||||||
return raw
|
return raw
|
||||||
}
|
}
|
||||||
|
|
||||||
// removeNewLines will replace `\r` and `\n` with an empty space
|
|
||||||
func removeNewLinesBytes(raw []byte) []byte {
|
|
||||||
var (
|
|
||||||
start = 0
|
|
||||||
// strings.IndexByte is faster than bytes.IndexByte
|
|
||||||
rawStr = utils.UnsafeString(raw) // b2s()
|
|
||||||
)
|
|
||||||
// check if a `\r` is present and save the position.
|
|
||||||
// if no `\r` is found, check if a `\n` is present,
|
|
||||||
if start = strings.IndexByte(rawStr, '\r'); start == -1 {
|
|
||||||
// check if a `\n` is present if no `\r` is found
|
|
||||||
if start = strings.IndexByte(rawStr, '\n'); start == -1 {
|
|
||||||
return raw
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// loop from start position to replace `\r` or `\n` with empty space
|
|
||||||
for i := start; i < len(raw); i++ {
|
|
||||||
// switch raw[i] {
|
|
||||||
// case '\r', '\n':
|
|
||||||
// raw[i] = ' '
|
|
||||||
// default:
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
if raw[i] != '\r' && raw[i] != '\n' {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
raw[i] = ' '
|
|
||||||
}
|
|
||||||
return raw
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scan stack if other methods match the request
|
// Scan stack if other methods match the request
|
||||||
func methodExist(ctx *Ctx) (exist bool) {
|
func methodExist(ctx *Ctx) (exist bool) {
|
||||||
for i := 0; i < len(intMethod); i++ {
|
for i := 0; i < len(intMethod); i++ {
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
package fiber
|
package fiber
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
@ -41,31 +40,6 @@ func Benchmark_RemoveNewLines(b *testing.B) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func Benchmark_RemoveNewLines_Bytes(b *testing.B) {
|
|
||||||
withNL := []byte("foo\r\nSet-Cookie:%20SESSIONID=MaliciousValue\r\n")
|
|
||||||
withoutNL := []byte("foo Set-Cookie:%20SESSIONID=MaliciousValue ")
|
|
||||||
expected := []byte("foo Set-Cookie:%20SESSIONID=MaliciousValue ")
|
|
||||||
var res []byte
|
|
||||||
|
|
||||||
b.Run("withoutNL", func(b *testing.B) {
|
|
||||||
b.ReportAllocs()
|
|
||||||
b.ResetTimer()
|
|
||||||
for n := 0; n < b.N; n++ {
|
|
||||||
res = removeNewLinesBytes(withoutNL)
|
|
||||||
}
|
|
||||||
utils.AssertEqual(b, true, bytes.Equal(res, expected))
|
|
||||||
})
|
|
||||||
|
|
||||||
b.Run("withNL", func(b *testing.B) {
|
|
||||||
b.ReportAllocs()
|
|
||||||
b.ResetTimer()
|
|
||||||
for n := 0; n < b.N; n++ {
|
|
||||||
res = removeNewLinesBytes(withNL)
|
|
||||||
}
|
|
||||||
utils.AssertEqual(b, true, bytes.Equal(res, expected))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// go test -v -run=RemoveNewLines_Bytes -count=3
|
// go test -v -run=RemoveNewLines_Bytes -count=3
|
||||||
func Test_RemoveNewLines_Bytes(t *testing.T) {
|
func Test_RemoveNewLines_Bytes(t *testing.T) {
|
||||||
app := New()
|
app := New()
|
||||||
|
@ -105,7 +79,6 @@ func Test_RemoveNewLines_Bytes(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// go test -v -run=Test_Utils_ -count=3
|
// go test -v -run=Test_Utils_ -count=3
|
||||||
func Test_Utils_ETag(t *testing.T) {
|
func Test_Utils_ETag(t *testing.T) {
|
||||||
app := New()
|
app := New()
|
||||||
|
|
Loading…
Reference in New Issue