From 525b5fa19ae8898bd1bd73a2b7ff76aefd8da0df Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 6 Oct 2018 17:28:40 -0400 Subject: [PATCH] null checks --- src/iOS.Autofill/CredentialProviderViewController.cs | 12 ++++++------ src/iOS.Core/Utilities/ASHelpers.cs | 10 +++++----- src/iOS.Core/Views/ExtensionTableSource.cs | 4 ++-- src/iOS/AppDelegate.cs | 6 +++--- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/iOS.Autofill/CredentialProviderViewController.cs b/src/iOS.Autofill/CredentialProviderViewController.cs index 1181d5ae3..4a3f42767 100644 --- a/src/iOS.Autofill/CredentialProviderViewController.cs +++ b/src/iOS.Autofill/CredentialProviderViewController.cs @@ -141,13 +141,13 @@ namespace Bit.iOS.Autofill public void CompleteRequest(string username = null, string password = null, string totp = null) { - if(_context.Configuring) + if((_context?.Configuring ?? true) && string.IsNullOrWhiteSpace(password)) { - ExtensionContext.CompleteExtensionConfigurationRequest(); + ExtensionContext?.CompleteExtensionConfigurationRequest(); return; } - if(string.IsNullOrWhiteSpace(username) && string.IsNullOrWhiteSpace(password)) + if(_context == null || string.IsNullOrWhiteSpace(password)) { _googleAnalyticsService.TrackAutofillExtensionEvent("Canceled"); var err = new NSError(new NSString("ASExtensionErrorDomain"), @@ -156,7 +156,7 @@ namespace Bit.iOS.Autofill { NSRunLoop.Main.BeginInvokeOnMainThread(() => { - ExtensionContext.CancelRequest(err); + ExtensionContext?.CancelRequest(err); }); }); return; @@ -173,7 +173,7 @@ namespace Bit.iOS.Autofill { NSRunLoop.Main.BeginInvokeOnMainThread(() => { - ExtensionContext.CompleteRequest(cred, null); + ExtensionContext?.CompleteRequest(cred, null); }); }); } @@ -233,7 +233,7 @@ namespace Bit.iOS.Autofill PerformSegue("setupSegue", this); return; } - if (_context.ServiceIdentifiers == null || _context.ServiceIdentifiers.Length == 0) + if(_context.ServiceIdentifiers == null || _context.ServiceIdentifiers.Length == 0) { PerformSegue("loginSearchSegue", this); } diff --git a/src/iOS.Core/Utilities/ASHelpers.cs b/src/iOS.Core/Utilities/ASHelpers.cs index b67b3435c..ac1692270 100644 --- a/src/iOS.Core/Utilities/ASHelpers.cs +++ b/src/iOS.Core/Utilities/ASHelpers.cs @@ -26,21 +26,21 @@ namespace Bit.iOS.Core.Utilities } if (identities.Any()) { - await ASCredentialIdentityStore.SharedStore.ReplaceCredentialIdentitiesAsync(identities.ToArray()); + await ASCredentialIdentityStore.SharedStore?.ReplaceCredentialIdentitiesAsync(identities.ToArray()); } } } public static async Task IdentitiesCanIncremental() { - var state = await ASCredentialIdentityStore.SharedStore.GetCredentialIdentityStoreStateAsync(); - return state.Enabled && state.SupportsIncrementalUpdates; + var state = await ASCredentialIdentityStore.SharedStore?.GetCredentialIdentityStoreStateAsync(); + return state != null && state.Enabled && state.SupportsIncrementalUpdates; } public static async Task AutofillEnabled() { - var state = await ASCredentialIdentityStore.SharedStore.GetCredentialIdentityStoreStateAsync(); - return state.Enabled; + var state = await ASCredentialIdentityStore.SharedStore?.GetCredentialIdentityStoreStateAsync(); + return state != null && state.Enabled; } public static async Task GetCipherIdentityAsync(string cipherId, ICipherService cipherService) diff --git a/src/iOS.Core/Views/ExtensionTableSource.cs b/src/iOS.Core/Views/ExtensionTableSource.cs index d9102d664..4abcbc8a1 100644 --- a/src/iOS.Core/Views/ExtensionTableSource.cs +++ b/src/iOS.Core/Views/ExtensionTableSource.cs @@ -81,9 +81,9 @@ namespace Bit.iOS.Core.Views { searchFilter = searchFilter.ToLower(); Items = _allItems - .Where(s => s.Name.ToLower().Contains(searchFilter) || + .Where(s => s.Name?.ToLower().Contains(searchFilter) ?? false || (s.Username?.ToLower().Contains(searchFilter) ?? false) || - (s.Uris?.FirstOrDefault()?.Uri.ToLower().Contains(searchFilter) ?? false)) + (s.Uris?.FirstOrDefault()?.Uri?.ToLower().Contains(searchFilter) ?? false)) .TakeWhile(s => !ct.IsCancellationRequested) .ToArray(); } diff --git a/src/iOS/AppDelegate.cs b/src/iOS/AppDelegate.cs index 097ebb918..5156e02a4 100644 --- a/src/iOS/AppDelegate.cs +++ b/src/iOS/AppDelegate.cs @@ -169,7 +169,7 @@ namespace Bit.iOS { return; } - await ASCredentialIdentityStore.SharedStore.SaveCredentialIdentitiesAsync( + await ASCredentialIdentityStore.SharedStore?.SaveCredentialIdentitiesAsync( new ASPasswordCredentialIdentity[] { identity }); return; } @@ -190,7 +190,7 @@ namespace Bit.iOS { return; } - await ASCredentialIdentityStore.SharedStore.RemoveCredentialIdentitiesAsync( + await ASCredentialIdentityStore.SharedStore?.RemoveCredentialIdentitiesAsync( new ASPasswordCredentialIdentity[] { identity }); return; } @@ -203,7 +203,7 @@ namespace Bit.iOS { if(_deviceInfoService.Version >= 12) { - await ASCredentialIdentityStore.SharedStore.RemoveAllCredentialIdentitiesAsync(); + await ASCredentialIdentityStore.SharedStore?.RemoveAllCredentialIdentitiesAsync(); } });