From f8d72f02311ced526e62423eed1214e57365911b Mon Sep 17 00:00:00 2001 From: Matt Gibson Date: Thu, 11 Jan 2024 09:55:16 -0500 Subject: [PATCH] [PM-5465] Fix null checks in login view uris (#7421) * Prefer empty lists to null * Defensively null check public properties --- .../src/vault/components/add-edit.component.ts | 2 +- .../src/vault/models/request/cipher.request.ts | 17 +++++++---------- libs/common/src/vault/models/view/login.view.ts | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/libs/angular/src/vault/components/add-edit.component.ts b/libs/angular/src/vault/components/add-edit.component.ts index ad5359a3c7..a38d070ab0 100644 --- a/libs/angular/src/vault/components/add-edit.component.ts +++ b/libs/angular/src/vault/components/add-edit.component.ts @@ -330,7 +330,7 @@ export class AddEditComponent implements OnInit, OnDestroy { this.cipher.login.uris.length === 1 && (this.cipher.login.uris[0].uri == null || this.cipher.login.uris[0].uri === "") ) { - this.cipher.login.uris = null; + this.cipher.login.uris = []; } // Allows saving of selected collections during "Add" and "Clone" flows diff --git a/libs/common/src/vault/models/request/cipher.request.ts b/libs/common/src/vault/models/request/cipher.request.ts index 58664495b1..68e0c6330d 100644 --- a/libs/common/src/vault/models/request/cipher.request.ts +++ b/libs/common/src/vault/models/request/cipher.request.ts @@ -46,7 +46,13 @@ export class CipherRequest { switch (this.type) { case CipherType.Login: this.login = new LoginApi(); - this.login.uris = null; + this.login.uris = + cipher.login.uris?.map((u) => { + const uri = new LoginUriApi(); + uri.uri = u.uri != null ? u.uri.encryptedString : null; + uri.match = u.match != null ? u.match : null; + return uri; + }) ?? []; this.login.username = cipher.login.username ? cipher.login.username.encryptedString : null; this.login.password = cipher.login.password ? cipher.login.password.encryptedString : null; this.login.passwordRevisionDate = @@ -56,15 +62,6 @@ export class CipherRequest { this.login.totp = cipher.login.totp ? cipher.login.totp.encryptedString : null; this.login.autofillOnPageLoad = cipher.login.autofillOnPageLoad; - if (cipher.login.uris != null) { - this.login.uris = cipher.login.uris.map((u) => { - const uri = new LoginUriApi(); - uri.uri = u.uri != null ? u.uri.encryptedString : null; - uri.match = u.match != null ? u.match : null; - return uri; - }); - } - if (cipher.login.fido2Credentials != null) { this.login.fido2Credentials = cipher.login.fido2Credentials.map((key) => { const keyApi = new Fido2CredentialApi(); diff --git a/libs/common/src/vault/models/view/login.view.ts b/libs/common/src/vault/models/view/login.view.ts index 5d2822dff6..59b21b901d 100644 --- a/libs/common/src/vault/models/view/login.view.ts +++ b/libs/common/src/vault/models/view/login.view.ts @@ -61,7 +61,7 @@ export class LoginView extends ItemView { } get hasUris(): boolean { - return this.uris.length > 0; + return this.uris != null && this.uris.length > 0; } get hasFido2Credentials(): boolean {