| 1 | package utilsscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/ |
| 2 | |
| 3 | import ( |
| 4 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 6 | "net/httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/" |
| 7 | "net/netipscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/" |
| 8 | "net/urlscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/" |
| 9 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 10 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 11 | "timescip-go gomod github.com/golang/go/src go1.25.0 time/" |
| 12 | |
| 13 | "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/" |
| 14 | ) |
| 15 | |
| 16 | // Differential edge-case suites for the helpers that promise byte-for-byte |
| 17 | // stdlib parity. Rather than hand-picking expectations, these enumerate |
| 18 | // structured input spaces — positional mutations, word-boundary offsets, |
| 19 | // malformed UTF-8, calendar boundaries — and require agreement with the |
| 20 | // stdlib reference on every input. |
| 21 | |
| 22 | func Test_ParseHTTPDate_AllMonthsAndWeekdaysscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Test_ParseHTTPDate_AllMonthsAndWeekdays().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 23 | t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().() |
| 24 | // Twelve months exercise every httpMonthNum case; seven consecutive |
| 25 | // days exercise every weekday name. |
| 26 | for month := timescip-go gomod github.com/golang/go/src go1.25.0 time/.Januaryscip-go gomod github.com/golang/go/src go1.25.0 time/January.; month <= timescip-go gomod github.com/golang/go/src go1.25.0 time/.Decemberscip-go gomod github.com/golang/go/src go1.25.0 time/December.; month++ { |
| 27 | tm := timescip-go gomod github.com/golang/go/src go1.25.0 time/.Datescip-go gomod github.com/golang/go/src go1.25.0 time/Date().(2021, month, 15, 1, 2, 3, 0, timescip-go gomod github.com/golang/go/src go1.25.0 time/.UTCscip-go gomod github.com/golang/go/src go1.25.0 time/UTC.) |
| 28 | got, err := ParseHTTPDatescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/ParseHTTPDate().(FormatHTTPDatescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/FormatHTTPDate().(tm)) |
| 29 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "month %v", month) |
| 30 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Truescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/True().(t, got.Equalscip-go gomod github.com/golang/go/src go1.25.0 time/Time#Equal().(tm), "month %v", month) |
| 31 | } |
| 32 | for day := 1; day <= 7; day++ { |
| 33 | tm := timescip-go gomod github.com/golang/go/src go1.25.0 time/.Datescip-go gomod github.com/golang/go/src go1.25.0 time/Date().(2021, timescip-go gomod github.com/golang/go/src go1.25.0 time/.Augustscip-go gomod github.com/golang/go/src go1.25.0 time/August., day, 23, 59, 59, 0, timescip-go gomod github.com/golang/go/src go1.25.0 time/.UTCscip-go gomod github.com/golang/go/src go1.25.0 time/UTC.) |
| 34 | got, err := ParseHTTPDatescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/ParseHTTPDate().(FormatHTTPDatescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/FormatHTTPDate().(tm)) |
| 35 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "day %d", day) |
| 36 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Truescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/True().(t, got.Equalscip-go gomod github.com/golang/go/src go1.25.0 time/Time#Equal().(tm), "day %d", day) |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | func Test_ParseHTTPDate_PositionalMutationsscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Test_ParseHTTPDate_PositionalMutations().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 41 | t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().() |
| 42 | base := "Sun, 06 Nov 1994 08:49:37 GMT" |
| 43 | replacements := []byte{' ', ':', ',', '-', '.', '0', '5', '9', 'A', 'M', 'a', 'z', 0x00, 0x7F, 0xFF} |
| 44 | for pos := range len(base) { |
| 45 | for _, r := range replacements { |
| 46 | mutated := base[:pos] + string(r) + base[pos+1:] |
| 47 | assertHTTPDateParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertHTTPDateParity().(t, mutated) |
| 48 | } |
| 49 | } |
| 50 | // Length mutations: truncations and extensions. |
| 51 | for cut := range len(base) { |
| 52 | assertHTTPDateParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertHTTPDateParity().(t, base[:cut]) |
| 53 | } |
| 54 | assertHTTPDateParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertHTTPDateParity().(t, base+" ") |
| 55 | assertHTTPDateParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertHTTPDateParity().(t, base+"X") |
| 56 | assertHTTPDateParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertHTTPDateParity().(t, " "+base) |
| 57 | assertHTTPDateParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertHTTPDateParity().(t, "\t"+base+"\r\n") |
| 58 | } |
| 59 | |
| 60 | func Test_ParseHTTPDate_CalendarBoundariesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Test_ParseHTTPDate_CalendarBoundaries().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 61 | t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().() |
| 62 | months := []string{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"} |
| 63 | years := []int{0, 4, 100, 400, 1900, 1996, 2000, 2020, 2023, 9999} |
| 64 | days := []int{0, 1, 28, 29, 30, 31, 32, 99} |
| 65 | for _, year := range years { |
| 66 | for _, month := range months { |
| 67 | for _, day := range days { |
| 68 | in := fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("Fri, %02d %s %04d 12:00:00 GMT", day, month, year) |
| 69 | assertHTTPDateParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertHTTPDateParity().(t, in) |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | // Clock-field boundaries. |
| 74 | for _, clock := range []string{"00:00:00", "23:59:59", "24:00:00", "23:60:00", "23:59:60", "99:99:99"} { |
| 75 | assertHTTPDateParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertHTTPDateParity().(t, "Sat, 15 Jul 2023 "+clock+" GMT") |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // assertHTTPDateParity requires ParseHTTPDate to agree with the |
| 80 | // net/http.ParseTime reference on outcome, instant, and location. |
| 81 | func assertHTTPDateParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertHTTPDateParity().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, in string) { |
| 82 | t.Helperscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Helper().() |
| 83 | want, wantErr := refParseHTTPDatescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/refParseHTTPDate().(in) |
| 84 | got, err := ParseHTTPDatescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/ParseHTTPDate().(in) |
| 85 | if wantErr != nil { |
| 86 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err, "input %q", in) |
| 87 | return |
| 88 | } |
| 89 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "input %q", in) |
| 90 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Truescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/True().(t, got.Equalscip-go gomod github.com/golang/go/src go1.25.0 time/Time#Equal().(want), "input %q: got %v, want %v", in, got, want) |
| 91 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, want.Locationscip-go gomod github.com/golang/go/src go1.25.0 time/Time#Location().().Stringscip-go gomod github.com/golang/go/src go1.25.0 time/Location#String().(), got.Locationscip-go gomod github.com/golang/go/src go1.25.0 time/Time#Location().().Stringscip-go gomod github.com/golang/go/src go1.25.0 time/Location#String().(), "input %q", in) |
| 92 | } |
| 93 | |
| 94 | func Test_AppendUnescape_LongAndBoundaryInputsscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Test_AppendUnescape_LongAndBoundaryInputs().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 95 | t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().() |
| 96 | long := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 strings/Repeat().("abcdefgh", 8) // 64B, engages the vectorized scans |
| 97 | inputs := []string{ |
| 98 | long, |
| 99 | long + "%", |
| 100 | long + "%4", |
| 101 | long + "%41", |
| 102 | long + "%zz", |
| 103 | "%41" + long, |
| 104 | long[:31] + "%" + long[:1], // '%' exactly at index 31 |
| 105 | stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 strings/Repeat().("+", 64), |
| 106 | stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 strings/Repeat().("%25", 32), |
| 107 | stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 strings/Repeat().("a+", 32), |
| 108 | "%", |
| 109 | "+", |
| 110 | "%%%", |
| 111 | "%+1", |
| 112 | "+%41+", |
| 113 | } |
| 114 | for _, in := range inputs { |
| 115 | assertUnescapeParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertUnescapeParity().(t, in) |
| 116 | } |
| 117 | |
| 118 | // A late error must still return the original dst content untouched. |
| 119 | got, err := AppendQueryUnescapescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/AppendQueryUnescape().([]byte("keep"), long+"%zz") |
| 120 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err) |
| 121 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, "keep", string(got)) |
| 122 | gotPath, err := AppendPathUnescapescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/AppendPathUnescape().([]byte("keep"), long+"%") |
| 123 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err) |
| 124 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, "keep", string(gotPath)) |
| 125 | } |
| 126 | |
| 127 | func Test_AppendUnescape_EveryEscapeBytescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Test_AppendUnescape_EveryEscapeByte().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 128 | t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().() |
| 129 | // Every byte in both positions of an escape pair, plus that byte alone |
| 130 | // after '%', pinned to net/url's accept set and error values. |
| 131 | for i := range 256 { |
| 132 | c := string([]byte{byte(i)}) |
| 133 | assertUnescapeParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertUnescapeParity().(t, "%"+c+"0ab") |
| 134 | assertUnescapeParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertUnescapeParity().(t, "%4"+c+"ab") |
| 135 | assertUnescapeParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertUnescapeParity().(t, "ab%"+c) |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | // assertUnescapeParity requires the two unescape helpers to agree with |
| 140 | // net/url on output and exact error values, for both instantiations. |
| 141 | func assertUnescapeParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertUnescapeParity().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, in string) { |
| 142 | t.Helperscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Helper().() |
| 143 | wantQ, wantQErr := urlscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/.QueryUnescapescip-go gomod github.com/golang/go/src go1.25.0 `net/url`/QueryUnescape().(in) |
| 144 | gotQ, errQ := AppendQueryUnescapescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/AppendQueryUnescape().(nil, in) |
| 145 | gotQB, errQB := AppendQueryUnescapescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/AppendQueryUnescape().([]byte(nil), []byte(in)) |
| 146 | wantP, wantPErr := urlscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/.PathUnescapescip-go gomod github.com/golang/go/src go1.25.0 `net/url`/PathUnescape().(in) |
| 147 | gotP, errP := AppendPathUnescapescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/AppendPathUnescape().(nil, in) |
| 148 | if wantQErr != nil { |
| 149 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, wantQErr, errQ, "query input %q", in) |
| 150 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, wantQErr, errQB, "query input %q", in) |
| 151 | } else { |
| 152 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, errQ, "query input %q", in) |
| 153 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, wantQ, string(gotQ), "query input %q", in) |
| 154 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, wantQ, string(gotQB), "query input %q", in) |
| 155 | } |
| 156 | if wantPErr != nil { |
| 157 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, wantPErr, errP, "path input %q", in) |
| 158 | } else { |
| 159 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, errP, "path input %q", in) |
| 160 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, wantP, string(gotP), "path input %q", in) |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | func Test_AppendEscape_EdgeCasesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Test_AppendEscape_EdgeCases().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 165 | t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().() |
| 166 | all := make([]byte, 256) |
| 167 | for i := range all { |
| 168 | all[i] = byte(i) |
| 169 | } |
| 170 | inputs := []string{ |
| 171 | string(all), |
| 172 | stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 strings/Repeat().(" ", 64), |
| 173 | stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 strings/Repeat().("%", 64), |
| 174 | stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 strings/Repeat().("a ", 32), |
| 175 | stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 strings/Repeat().("unreserved-only.~_", 16), |
| 176 | "ends with unsafe/", |
| 177 | "/starts with unsafe", |
| 178 | } |
| 179 | for _, in := range inputs { |
| 180 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, urlscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/.QueryEscapescip-go gomod github.com/golang/go/src go1.25.0 `net/url`/QueryEscape().(in), string(AppendQueryEscapescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/AppendQueryEscape().(nil, in)), "input %q", in) |
| 181 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, urlscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/.PathEscapescip-go gomod github.com/golang/go/src go1.25.0 `net/url`/PathEscape().(in), string(AppendPathEscapescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/AppendPathEscape().(nil, in)), "input %q", in) |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | func Test_AppendJSONString_BoundaryOffsetsscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Test_AppendJSONString_BoundaryOffsets().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 186 | t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().() |
| 187 | // Each special byte or sequence at every offset around the SWAR word |
| 188 | // width, so escapes land in every lane and on both sides of the |
| 189 | // word-loop/tail split. |
| 190 | specials := []string{ |
| 191 | "\"", "\\", "\n", "\r", "\t", "\b", "\f", "\x00", "\x1f", "\x7f", |
| 192 | "<", ">", "&", "\xff", "\xc3\xa9", "\u2028", "\u2029", "\xf0\x9f\x98\x80", "\xc3", |
| 193 | } |
| 194 | for _, sp := range specials { |
| 195 | for pad := range 18 { |
| 196 | in := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 strings/Repeat().("a", pad) + sp + stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 strings/Repeat().("b", 17-pad) |
| 197 | assertJSONStringParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertJSONStringParity().(t, in) |
| 198 | // And with the special at the very end, where the tail paths run. |
| 199 | assertJSONStringParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertJSONStringParity().(t, stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 strings/Repeat().("a", pad)+sp) |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | func Test_AppendJSONString_UTF8EdgeCasesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Test_AppendJSONString_UTF8EdgeCases().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 205 | t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().() |
| 206 | inputs := []string{ |
| 207 | "\xc0\x80", // overlong NUL |
| 208 | "\xc1\xbf", // overlong |
| 209 | "\xe0\x80\xaf", // overlong 3-byte |
| 210 | "\xed\xa0\x80", // UTF-16 surrogate half |
| 211 | "\xed\xbf\xbf", // UTF-16 surrogate half |
| 212 | "\xf4\x8f\xbf\xbf", // U+10FFFF, highest valid rune |
| 213 | "\xf4\x90\x80\x80", // just above U+10FFFF |
| 214 | "\xf8\x88\x80\x80\x80", // 5-byte form |
| 215 | "\x80", // lone continuation |
| 216 | "\xbf\xbf", // lone continuations |
| 217 | "\xc3", // truncated 2-byte |
| 218 | "\xe2\x80", // truncated 3-byte (prefix of U+2028) |
| 219 | "\xf0\x9f\x98", // truncated 4-byte |
| 220 | "\xef\xbb\xbfBOM", // BOM prefix |
| 221 | "ok\xc3\xa9\xc3", // valid then truncated |
| 222 | "\xe2\x80\xa8\xe2\x80\xa9\xe2\x80\xaa", // U+2028, U+2029, then U+202A (unescaped) |
| 223 | stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 strings/Repeat().("\xff", 32), |
| 224 | stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 strings/Repeat().("\xc3\xa9", 16), |
| 225 | } |
| 226 | for _, in := range inputs { |
| 227 | assertJSONStringParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertJSONStringParity().(t, in) |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | // assertJSONStringParity requires AppendJSONString to agree with |
| 232 | // encoding/json.Marshal byte for byte, for both instantiations. |
| 233 | func assertJSONStringParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertJSONStringParity().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, in string) { |
| 234 | t.Helperscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Helper().() |
| 235 | want, err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Marshal().(in) |
| 236 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 237 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, string(want), string(AppendJSONStringscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/AppendJSONString().(nil, in)), "input %q", in) |
| 238 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, string(want), string(AppendJSONStringscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/AppendJSONString().(nil, []byte(in))), "input %q", in) |
| 239 | } |
| 240 | |
| 241 | func Test_ParseIP_PositionalMutationsscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Test_ParseIP_PositionalMutations().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 242 | t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().() |
| 243 | bases := []string{ |
| 244 | "203.0.113.195", |
| 245 | "::1", |
| 246 | "2001:db8::8a2e:370:7334", |
| 247 | "1:2:3:4:5:6:7:8", |
| 248 | "::ffff:1.2.3.4", |
| 249 | "1:2:3:4:5:6:1.2.3.4", |
| 250 | "fe80::1%eth0", |
| 251 | } |
| 252 | replacements := []byte{'.', ':', '%', '0', '9', 'a', 'f', 'g', 'G', '-', ' ', 0x00, 0xFF} |
| 253 | for _, base := range bases { |
| 254 | for pos := range len(base) { |
| 255 | for _, r := range replacements { |
| 256 | assertParseIPParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertParseIPParity().(t, base[:pos]+string(r)+base[pos+1:]) |
| 257 | } |
| 258 | assertParseIPParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertParseIPParity().(t, base[:pos]) // every truncation |
| 259 | } |
| 260 | assertParseIPParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertParseIPParity().(t, base+":") |
| 261 | assertParseIPParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertParseIPParity().(t, base+".") |
| 262 | assertParseIPParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertParseIPParity().(t, base+"0") |
| 263 | assertParseIPParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertParseIPParity().(t, base+"%") |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | func Test_ParseIP_MoreEdgeCasesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Test_ParseIP_MoreEdgeCases().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 268 | t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().() |
| 269 | inputs := []string{ |
| 270 | "1;2", // field followed by a non-separator byte |
| 271 | "1:2;3", // same, after a valid group |
| 272 | "fe80::1%%", // zone containing '%' |
| 273 | "1::2%", // empty zone after valid address |
| 274 | "::%25eth0", |
| 275 | "1:2:3:4:5:6:7:8%eth0", // full address with zone |
| 276 | "0.0.0.256", |
| 277 | "0.0.0.00", |
| 278 | "255.255.255.2555", |
| 279 | "::0.0.0.0", |
| 280 | "0::00:0:00:0.0.0.0", |
| 281 | "1:2:3:4:5:1.2.3.4", // v4 tail too early without ellipsis |
| 282 | "1:2:3:4:5:6:7:1.2.3.4", // v4 tail too late |
| 283 | "::ffff:016.1.2.3", |
| 284 | "ABCD:EF01:2345:6789:abcd:ef01:2345:6789", |
| 285 | "0000:0000:0000:0000:0000:0000:0000:0000", |
| 286 | "00000::", |
| 287 | "::00000", |
| 288 | "2:2:2:2:2:2:2:2:", |
| 289 | "\x00::", |
| 290 | "1.2.3.4%eth0", // zones are IPv6-only |
| 291 | } |
| 292 | for _, in := range inputs { |
| 293 | assertParseIPParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertParseIPParity().(t, in) |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | // assertParseIPParity requires ParseIPv4/ParseIPv6 to accept exactly the |
| 298 | // per-family netip.ParseAddr inputs and produce identical addresses, for |
| 299 | // both instantiations. |
| 300 | func assertParseIPParityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/assertParseIPParity().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, in string) { |
| 301 | t.Helperscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Helper().() |
| 302 | want, wantErr := netipscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/.ParseAddrscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/ParseAddr().(in) |
| 303 | hasColon := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ContainsRunescip-go gomod github.com/golang/go/src go1.25.0 strings/ContainsRune().(in, ':') |
| 304 | |
| 305 | got4, ok4 := ParseIPv4scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/ParseIPv4().(in) |
| 306 | _, ok4B := ParseIPv4scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/ParseIPv4().([]byte(in)) |
| 307 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, wantErr == nil && !hasColon, ok4, "ParseIPv4 input %q (netip err: %v)", in, wantErr) |
| 308 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, ok4, ok4B, "ParseIPv4 bytes input %q", in) |
| 309 | if ok4 { |
| 310 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, want, got4, "ParseIPv4 input %q", in) |
| 311 | } else { |
| 312 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, netipscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/.Addrscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/Addr#{}, got4, "ParseIPv4 input %q", in) |
| 313 | } |
| 314 | |
| 315 | got6, ok6 := ParseIPv6scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/ParseIPv6().(in) |
| 316 | _, ok6B := ParseIPv6scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/ParseIPv6().([]byte(in)) |
| 317 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, wantErr == nil && hasColon, ok6, "ParseIPv6 input %q (netip err: %v)", in, wantErr) |
| 318 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, ok6, ok6B, "ParseIPv6 bytes input %q", in) |
| 319 | if ok6 { |
| 320 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, want, got6, "ParseIPv6 input %q", in) |
| 321 | } else { |
| 322 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, netipscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/.Addrscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/Addr#{}, got6, "ParseIPv6 input %q", in) |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | func Test_CanonicalHeaderKey_PositionalMutationsscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Test_CanonicalHeaderKey_PositionalMutations().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 327 | t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().() |
| 328 | bases := []string{"content-type", "X-Request-Id", "a", "-", "--", "a-", "-a", "A--b"} |
| 329 | for _, base := range bases { |
| 330 | for pos := range len(base) { |
| 331 | for c := range 256 { |
| 332 | in := base[:pos] + string(byte(c)) + base[pos+1:] |
| 333 | want := httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.CanonicalHeaderKeyscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/CanonicalHeaderKey().(in) |
| 334 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, want, CanonicalHeaderKeyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/CanonicalHeaderKey().(in), "input %q", in) |
| 335 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, want, string(CanonicalHeaderKeyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/CanonicalHeaderKey().([]byte(in))), "input %q", in) |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | func Test_CanonicalHeaderKey_InputImmutabilityscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Test_CanonicalHeaderKey_InputImmutability().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 342 | t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().() |
| 343 | // The rewrite path must copy, never mutate the caller's bytes. |
| 344 | in := []byte("content-TYPE") |
| 345 | out := CanonicalHeaderKeyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/CanonicalHeaderKey().(in) |
| 346 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, "content-TYPE", string(in)) |
| 347 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, "Content-Type", string(out)) |
| 348 | } |