Skip to content

Commit ee6382e

Browse files
committed
dom: use cookie jar's allocator to parse cookie
1 parent 0310192 commit ee6382e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/html/document.zig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,12 @@ pub const HTMLDocument = struct {
9090
return buf.items;
9191
}
9292

93-
pub fn set_cookie(_: *parser.DocumentHTML, arena: std.mem.Allocator, userctx: UserContext, cookie_str: []const u8) ![]const u8 {
94-
const c = try Cookie.parse(arena, &userctx.url.uri, cookie_str);
93+
pub fn set_cookie(_: *parser.DocumentHTML, userctx: UserContext, cookie_str: []const u8) ![]const u8 {
94+
// we use the cookie jar's allocator to parse the cookie because it
95+
// outlives the page's arena.
96+
const c = try Cookie.parse(userctx.cookie_jar.allocator, &userctx.url.uri, cookie_str);
97+
errdefer c.deinit();
98+
9599
try userctx.cookie_jar.add(c, std.time.timestamp());
96100

97101
return cookie_str;

0 commit comments

Comments
 (0)