From 5c5cbeb4910c0a61b9ef95bc1c774bab0ec0cc7a Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 10 Jan 2024 07:05:15 -0500 Subject: [PATCH] LibSQL+LibWebView: Do not manually serialize time stamps in CookieJar LibSQL supports serializing time stamps as of commit effcd080ca802515ddce8392c70df512b509f57c. However, that commit serializes the timestamps as milliseconds, whereas the CookieJar was serializing them as seconds. In retrospect, these should have been updated in unison, along with the SQL heap version (as this is a serialization change that affects the file format). So this patch also updates the version, as this is not a backwards compatible change. --- Userland/Libraries/LibSQL/Heap.h | 2 +- Userland/Libraries/LibWebView/CookieJar.cpp | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibSQL/Heap.h b/Userland/Libraries/LibSQL/Heap.h index b3fe5f3018..3c216eb37f 100644 --- a/Userland/Libraries/LibSQL/Heap.h +++ b/Userland/Libraries/LibSQL/Heap.h @@ -66,7 +66,7 @@ private: */ class Heap : public RefCounted { public: - static constexpr u32 VERSION = 4; + static constexpr u32 VERSION = 5; static ErrorOr> create(ByteString); virtual ~Heap(); diff --git a/Userland/Libraries/LibWebView/CookieJar.cpp b/Userland/Libraries/LibWebView/CookieJar.cpp index 1688d1693e..f9731979a1 100644 --- a/Userland/Libraries/LibWebView/CookieJar.cpp +++ b/Userland/Libraries/LibWebView/CookieJar.cpp @@ -484,8 +484,7 @@ static ErrorOr parse_cookie(ReadonlySpan row) if (value.type() != SQL::SQLType::Integer) return Error::from_string_view(name); - auto time = value.to_int().value(); - field = UnixDateTime::from_seconds_since_epoch(time); + field = value.to_unix_date_time().value(); return {}; }; @@ -528,9 +527,9 @@ void CookieJar::insert_cookie_into_database(Web::Cookie::Cookie const& cookie) cookie.name.to_byte_string(), cookie.value.to_byte_string(), to_underlying(cookie.same_site), - cookie.creation_time.seconds_since_epoch(), - cookie.last_access_time.seconds_since_epoch(), - cookie.expiry_time.seconds_since_epoch(), + cookie.creation_time, + cookie.last_access_time, + cookie.expiry_time, cookie.domain.to_byte_string(), cookie.path.to_byte_string(), cookie.secure, @@ -552,9 +551,9 @@ void CookieJar::update_cookie_in_database(Web::Cookie::Cookie const& cookie) storage.statements.update_cookie, {}, [this]() { purge_expired_cookies(); }, {}, cookie.value.to_byte_string(), to_underlying(cookie.same_site), - cookie.creation_time.seconds_since_epoch(), - cookie.last_access_time.seconds_since_epoch(), - cookie.expiry_time.seconds_since_epoch(), + cookie.creation_time, + cookie.last_access_time, + cookie.expiry_time, cookie.secure, cookie.http_only, cookie.host_only,