From 1b75261f686a7afeae087740cbcf9a67232b8e15 Mon Sep 17 00:00:00 2001 From: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com> Date: Fri, 30 Aug 2024 16:35:58 -0400 Subject: [PATCH] Fix web vault lock throwing an error (#10833) --- apps/web/src/app/vault/utils/collection-utils.spec.ts | 11 +++++++++++ apps/web/src/app/vault/utils/collection-utils.ts | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/apps/web/src/app/vault/utils/collection-utils.spec.ts b/apps/web/src/app/vault/utils/collection-utils.spec.ts index bf84b3155b..916ed8ff32 100644 --- a/apps/web/src/app/vault/utils/collection-utils.spec.ts +++ b/apps/web/src/app/vault/utils/collection-utils.spec.ts @@ -24,5 +24,16 @@ describe("CollectionUtils Service", () => { expect(result[0].node.name).toBe("Parent"); expect(result[0].children[0].node.name).toBe("Child"); }); + + it("should return an empty array if no collections are provided", () => { + // Arrange + const collections: CollectionView[] = []; + + // Act + const result = getNestedCollectionTree(collections); + + // Assert + expect(result).toEqual([]); + }); }); }); diff --git a/apps/web/src/app/vault/utils/collection-utils.ts b/apps/web/src/app/vault/utils/collection-utils.ts index cb995fd8ff..b035c40f9f 100644 --- a/apps/web/src/app/vault/utils/collection-utils.ts +++ b/apps/web/src/app/vault/utils/collection-utils.ts @@ -14,6 +14,10 @@ export function getNestedCollectionTree(collections: CollectionView[]): TreeNode export function getNestedCollectionTree( collections: (CollectionView | CollectionAdminView)[], ): TreeNode[] { + if (!collections) { + return []; + } + // Collections need to be cloned because ServiceUtils.nestedTraverse actively // modifies the names of collections. // These changes risk affecting collections store in StateService.