Skip to content

Commit

Permalink
fix: strip query param from keys
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 8, 2023
1 parent 313628b commit cc3ebb7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/utils.ts
Expand Up @@ -41,7 +41,11 @@ export function normalizeKey(key?: string) {
if (!key) {
return "";
}
return key.replace(/[/\\]/g, ":").replace(/:+/g, ":").replace(/^:|:$/g, "");
return key
.split("?")[0]
.replace(/[/\\]/g, ":")
.replace(/:+/g, ":")
.replace(/^:|:$/g, "");
}

export function joinKeys(...keys: string[]) {
Expand Down
4 changes: 3 additions & 1 deletion test/drivers/utils.ts
Expand Up @@ -33,13 +33,15 @@ export function testDriver(opts: TestOptions) {
it("setItem", async () => {
await ctx.storage.setItem("s1:a", "test_data");
await ctx.storage.setItem("s2:a", "test_data");
await ctx.storage.setItem("s3:a?q=1", "test_data");
expect(await ctx.storage.hasItem("s1:a")).toBe(true);
expect(await ctx.storage.getItem("s1:a")).toBe("test_data");
expect(await ctx.storage.getItem("s3:a?q=2")).toBe("test_data");
});

it("getKeys", async () => {
expect(await ctx.storage.getKeys().then((k) => k.sort())).toMatchObject(
["s1:a", "s2:a"].sort()
["s1:a", "s2:a", "s3:a"].sort()
);
expect(await ctx.storage.getKeys("s1").then((k) => k.sort())).toMatchObject(
["s1:a"].sort()
Expand Down

0 comments on commit cc3ebb7

Please sign in to comment.