Skip to content

Commit

Permalink
refactor(cookie): trim cookie on read (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
kawre committed May 5, 2024
1 parent a92e764 commit 458da8e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lua/leetcode/cache/cookie.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ function Cookie.delete()
return pcall(path.rm, file)
end

---@return string|nil
function Cookie.read()
local contents = file:read()

if not contents or type(contents) ~= "string" then
return
end

return select(1, contents:gsub("^%s*(.-)%s*$", "%1"))
end

---@return lc.cache.Cookie | nil
function Cookie.get()
if not file:exists() then
Expand All @@ -55,8 +66,8 @@ function Cookie.get()
return hcookie
end

local contents = file:read()
if not contents or type(contents) ~= "string" then
local contents = Cookie.read()
if not contents then
require("leetcode.command").delete_cookie()
return
end
Expand Down

0 comments on commit 458da8e

Please sign in to comment.