Skip to content

Commit 12aa9f4

Browse files
authored
Added guard to split not to get out of bounds exception when testing (#288)
* added guard to split not to get out of bounds exception when testing * reverting Session() returning nil if session does not exist (issue #287)
1 parent 8a33b63 commit 12aa9f4

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

tester/tester.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,23 @@ func Options(t *testing.T, newStore storeFactory) {
249249
r.ServeHTTP(res5, req5)
250250

251251
for _, c := range res1.Header().Values("Set-Cookie") {
252-
s := strings.Split(c, ";")
253-
if s[1] != " Path=/foo/bar/bat" {
254-
t.Error("Error writing path with options:", s[1])
252+
s := strings.Split(c, "; ")
253+
if len(s) < 2 {
254+
t.Fatal("No Path=/foo/bar/batt found in options")
255+
}
256+
if s[1] != "Path=/foo/bar/bat" {
257+
t.Fatal("Error writing path with options:", s[1])
255258
}
256259
}
257260

258261
for _, c := range res2.Header().Values("Set-Cookie") {
259-
s := strings.Split(c, ";")
260-
if s[1] != " Domain=localhost" {
261-
t.Error("Error writing domain with options:", s[1])
262+
s := strings.Split(c, "; ")
263+
if len(s) < 2 {
264+
t.Fatal("No Domain=localhost found in options")
265+
}
266+
267+
if s[1] != "Domain=localhost" {
268+
t.Fatal("Error writing domain with options:", s[1])
262269
}
263270
}
264271
}

tester/tester_options_samesite_go1.11.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ func testOptionSameSitego(t *testing.T, r *gin.Engine) {
2929
req3, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, "/sameSite", nil)
3030
r.ServeHTTP(res3, req3)
3131

32-
s := strings.Split(res3.Header().Get("Set-Cookie"), ";")
33-
if s[1] != " SameSite=Strict" {
34-
t.Error("Error writing samesite with options:", s[1])
32+
s := strings.Split(res3.Header().Get("Set-Cookie"), "; ")
33+
if len(s) < 2 {
34+
t.Fatal("No SameSite=Strict found in options")
35+
}
36+
if s[1] != "SameSite=Strict" {
37+
t.Fatal("Error writing samesite with options:", s[1])
3538
}
3639
}

0 commit comments

Comments
 (0)