From 126fbdfd60bd6dedb2c7d2cac2a9aa7d3075f89b Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Wed, 20 Feb 2019 23:03:04 +0900 Subject: [PATCH] Fix null reference exception if the NotificationUrl is not set --- BTCPayServer/Controllers/InvoiceController.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/BTCPayServer/Controllers/InvoiceController.cs b/BTCPayServer/Controllers/InvoiceController.cs index 4ca776621..0338db499 100644 --- a/BTCPayServer/Controllers/InvoiceController.cs +++ b/BTCPayServer/Controllers/InvoiceController.cs @@ -75,9 +75,6 @@ namespace BTCPayServer.Controllers var getAppsTaggingStore = _InvoiceRepository.GetAppsTaggingStore(store.Id); var storeBlob = store.GetStoreBlob(); - Uri notificationUri = Uri.IsWellFormedUriString(invoice.NotificationURL, UriKind.Absolute) ? new Uri(invoice.NotificationURL, UriKind.Absolute) : null; - if (notificationUri == null || (notificationUri.Scheme != "http" && notificationUri.Scheme != "https")) //TODO: Filer non routable addresses ? - notificationUri = null; EmailAddressAttribute emailValidator = new EmailAddressAttribute(); entity.ExpirationTime = entity.InvoiceTime.AddMinutes(storeBlob.InvoiceExpiration); entity.MonitoringExpiration = entity.ExpirationTime + TimeSpan.FromMinutes(storeBlob.MonitoringExpiration); @@ -85,7 +82,12 @@ namespace BTCPayServer.Controllers entity.ServerUrl = serverUrl; entity.FullNotifications = invoice.FullNotifications || invoice.ExtendedNotifications; entity.ExtendedNotifications = invoice.ExtendedNotifications; - entity.NotificationURL = notificationUri?.AbsoluteUri; + if (invoice.NotificationURL != null && + Uri.TryCreate(invoice.NotificationURL, UriKind.Absolute, out var notificationUri) && + (notificationUri.Scheme == "http" || notificationUri.Scheme == "https")) + { + entity.NotificationURL = notificationUri.AbsoluteUri; + } entity.NotificationEmail = invoice.NotificationEmail; entity.BuyerInformation = Map(invoice); entity.PaymentTolerance = storeBlob.PaymentTolerance;