Skip to content

Commit bf38b05

Browse files
committed
refactor(cookie): trim cookie on read (#80)
1 parent a92e764 commit bf38b05

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Diff for: lua/leetcode/cache/cookie.lua

+13-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ function Cookie.delete()
4141
return pcall(path.rm, file)
4242
end
4343

44+
---@return string|nil
45+
function Cookie.read()
46+
local contents = file:read()
47+
48+
if not contents or type(contents) ~= "string" then
49+
return
50+
end
51+
52+
return select(1, contents:gsub("^%s*(.-)%s*$", "%1"))
53+
end
54+
4455
---@return lc.cache.Cookie | nil
4556
function Cookie.get()
4657
if not file:exists() then
@@ -55,8 +66,8 @@ function Cookie.get()
5566
return hcookie
5667
end
5768

58-
local contents = file:read()
59-
if not contents or type(contents) ~= "string" then
69+
local contents = Cookie.read()
70+
if not contents then
6071
require("leetcode.command").delete_cookie()
6172
return
6273
end

0 commit comments

Comments
 (0)