From ee596c2c8d45a809d2bc6f03e7f9317819accd78 Mon Sep 17 00:00:00 2001 From: Fenny <25108519+Fenny@users.noreply.github.com> Date: Wed, 11 Nov 2020 18:43:56 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8B=20remove=20unused=20fn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helpers.go | 31 ------------------------------- helpers_test.go | 27 --------------------------- 2 files changed, 58 deletions(-) diff --git a/helpers.go b/helpers.go index 40d4f590..8c53cbf4 100644 --- a/helpers.go +++ b/helpers.go @@ -117,37 +117,6 @@ func removeNewLines(raw string) string { 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 func methodExist(ctx *Ctx) (exist bool) { for i := 0; i < len(intMethod); i++ { diff --git a/helpers_test.go b/helpers_test.go index c73f6040..3c085aed 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -5,7 +5,6 @@ package fiber import ( - "bytes" "crypto/tls" "fmt" "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 func Test_RemoveNewLines_Bytes(t *testing.T) { app := New() @@ -105,7 +79,6 @@ func Test_RemoveNewLines_Bytes(t *testing.T) { }) } - // go test -v -run=Test_Utils_ -count=3 func Test_Utils_ETag(t *testing.T) { app := New()