From 393ac0d60b53f3c4a9b2a6504d250cbada55b546 Mon Sep 17 00:00:00 2001 From: kvii <56432636+kvii@users.noreply.github.com> Date: Sat, 7 Dec 2024 22:51:24 +0800 Subject: [PATCH] feat: map session cookie expires to zero time value #1159 (#1160) --- lib/proto/a_interface_test.go | 5 +++++ lib/proto/a_patch.go | 3 +++ 2 files changed, 8 insertions(+) diff --git a/lib/proto/a_interface_test.go b/lib/proto/a_interface_test.go index 93ea4e0a..c7578204 100644 --- a/lib/proto/a_interface_test.go +++ b/lib/proto/a_interface_test.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "reflect" + "time" "github.com/go-rod/rod/lib/proto" "github.com/go-rod/rod/lib/utils" @@ -73,6 +74,10 @@ func (t T) TimeCodec() { data, err = json.Marshal(datetime) t.E(err) t.Eq(raw, data) + + var sessionExpires proto.TimeSinceEpoch = -1 + var zeroTime time.Time + t.Eq(sessionExpires.Time(), zeroTime) } func (t T) Rect() { diff --git a/lib/proto/a_patch.go b/lib/proto/a_patch.go index 3d5c5d54..f1c8cc05 100644 --- a/lib/proto/a_patch.go +++ b/lib/proto/a_patch.go @@ -16,6 +16,9 @@ type TimeSinceEpoch float64 // Time interface. func (t TimeSinceEpoch) Time() time.Time { + if t == -1 { + return time.Time{} + } return (time.Unix(0, 0)).Add( time.Duration(t * TimeSinceEpoch(time.Second)), )