Skip to content

Commit

Permalink
fix: parse filter code lose (#47)
Browse files Browse the repository at this point in the history
Co-authored-by: Potter <[email protected]>
  • Loading branch information
yxw007 and Potter authored Jul 25, 2024
1 parent fec694a commit d510919
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/cookie/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export function parse(
}

const key = str.slice(index, eqIdx).trim();
if (opt?.filter && !opt?.filter(key)) {
index = endIdx + 1;
continue;
}

// only assign once
if (undefined === obj[key as keyof typeof obj]) {
Expand Down
4 changes: 2 additions & 2 deletions test/cookie-parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ describe("cookie.parse(str, options)", () => {
parse("a=1;b=2", {
filter: (key) => key === "a",
}),
).toMatchObject({ a: "1" });
).toEqual({ a: "1" });

expect(parse("a=1;b=2")).toMatchObject({ a: "1", b: "2" });
expect(parse("a=1;b=2")).toEqual({ a: "1", b: "2" });
});
});
});

0 comments on commit d510919

Please sign in to comment.