From 99da8a69e7260b72e55d7214ec96f6ac5e759f35 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Thu, 9 Mar 2023 17:58:51 +0530 Subject: fix(ext/webstorage): check size of inputs before insert (#18087) --- cli/tests/unit/webstorage_test.ts | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'cli/tests') diff --git a/cli/tests/unit/webstorage_test.ts b/cli/tests/unit/webstorage_test.ts index 25813ac03..e6ca5bb88 100644 --- a/cli/tests/unit/webstorage_test.ts +++ b/cli/tests/unit/webstorage_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // deno-lint-ignore-file no-explicit-any -import { assert } from "./test_util.ts"; +import { assert, assertThrows } from "./test_util.ts"; Deno.test({ permissions: "none" }, function webStoragesReassignable() { // Can reassign to web storages @@ -11,3 +11,32 @@ Deno.test({ permissions: "none" }, function webStoragesReassignable() { assert(globalThis.localStorage instanceof globalThis.Storage); assert(globalThis.sessionStorage instanceof globalThis.Storage); }); + +Deno.test(function webstorageSizeLimit() { + localStorage.clear(); + assertThrows( + () => { + localStorage.setItem("k", "v".repeat(15 * 1024 * 1024)); + }, + Error, + "Exceeded maximum storage size", + ); + assert(localStorage.getItem("k") === null); + assertThrows( + () => { + localStorage.setItem("k".repeat(15 * 1024 * 1024), "v"); + }, + Error, + "Exceeded maximum storage size", + ); + assertThrows( + () => { + localStorage.setItem( + "k".repeat(5 * 1024 * 1024), + "v".repeat(5 * 1024 * 1024), + ); + }, + Error, + "Exceeded maximum storage size", + ); +}); -- cgit v1.2.3