From 02953b665d25914d090532fd5b1cfdd3144c42fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Thierry=20K=C3=A9chichian?= Date: Fri, 29 Dec 2023 04:36:33 +0100 Subject: [PATCH] FormLocationKey ArgumentNullException (#14936) --- .../Activities/HttpRedirectToFormLocationTask.cs | 9 +++------ .../HttpRedirectToFormLocationTask.Fields.Edit.cshtml | 2 +- .../Http/Activities/HttpRequestEvent.cs | 11 ++++------- .../Views/Items/HttpRequestEvent.Fields.Edit.cshtml | 4 ++-- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Forms/Activities/HttpRedirectToFormLocationTask.cs b/src/OrchardCore.Modules/OrchardCore.Forms/Activities/HttpRedirectToFormLocationTask.cs index 5c69952bae9..b1e6d64b7d5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Forms/Activities/HttpRedirectToFormLocationTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Forms/Activities/HttpRedirectToFormLocationTask.cs @@ -32,8 +32,8 @@ public override IEnumerable GetPossibleOutcomes(WorkflowExecutionContex public string FormLocationKey { - get => GetProperty(); - set => SetProperty(value); + get => GetProperty(() => string.Empty); + set => SetProperty(value ?? string.Empty); } public override Task ExecuteAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext) @@ -41,10 +41,7 @@ public override Task ExecuteAsync(WorkflowExecutionCont if (workflowContext.Output.TryGetValue(WorkflowConstants.HttpFormLocationOutputKeyName, out var obj) && obj is Dictionary formLocations) { - // if no custom location-key was provided, we use empty string as the default key. - var location = FormLocationKey ?? string.Empty; - - if (formLocations.TryGetValue(location, out var path)) + if (formLocations.TryGetValue(FormLocationKey, out var path)) { _httpContextAccessor.HttpContext.Items[WorkflowConstants.FormOriginatedLocationItemsKey] = path; diff --git a/src/OrchardCore.Modules/OrchardCore.Forms/Views/Items/HttpRedirectToFormLocationTask.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Forms/Views/Items/HttpRedirectToFormLocationTask.Fields.Edit.cshtml index 0103d6f9622..287b87ea431 100644 --- a/src/OrchardCore.Modules/OrchardCore.Forms/Views/Items/HttpRedirectToFormLocationTask.Fields.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Forms/Views/Items/HttpRedirectToFormLocationTask.Fields.Edit.cshtml @@ -6,5 +6,5 @@ - @T["This value needs to correspond with the Form Location Key value utilized in the HTTP request event settings. Leave blank if the workflow handles a single form event."] + @T["This key name should be equal to the 'Form Location Key' of the HTTP request event. Leave blank if the workflow only handles a single form."] diff --git a/src/OrchardCore.Modules/OrchardCore.Workflows/Http/Activities/HttpRequestEvent.cs b/src/OrchardCore.Modules/OrchardCore.Workflows/Http/Activities/HttpRequestEvent.cs index 9eb46001d4b..a1fdcec43cf 100644 --- a/src/OrchardCore.Modules/OrchardCore.Workflows/Http/Activities/HttpRequestEvent.cs +++ b/src/OrchardCore.Modules/OrchardCore.Workflows/Http/Activities/HttpRequestEvent.cs @@ -55,8 +55,8 @@ public int TokenLifeSpan public string FormLocationKey { - get => GetProperty(); - set => SetProperty(value); + get => GetProperty(() => string.Empty); + set => SetProperty(value ?? string.Empty); } public override bool CanExecute(WorkflowExecutionContext workflowContext, ActivityContext activityContext) @@ -77,13 +77,10 @@ public override Task ExecuteAsync(WorkflowExecutionCont if (!workflowContext.Output.TryGetValue(WorkflowConstants.HttpFormLocationOutputKeyName, out var obj) || obj is not Dictionary formLocation) { - formLocation = new Dictionary(); + formLocation = []; } - // if no custom location-key was provided, we use empty string as the default key. - var location = FormLocationKey ?? string.Empty; - - formLocation[location] = GetLocationUrl(value); + formLocation[FormLocationKey] = GetLocationUrl(value); workflowContext.Output[WorkflowConstants.HttpFormLocationOutputKeyName] = formLocation; } diff --git a/src/OrchardCore.Modules/OrchardCore.Workflows/Views/Items/HttpRequestEvent.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Workflows/Views/Items/HttpRequestEvent.Fields.Edit.cshtml index 7b5f64ad025..1b1f4e79c6f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Workflows/Views/Items/HttpRequestEvent.Fields.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Workflows/Views/Items/HttpRequestEvent.Fields.Edit.cshtml @@ -41,10 +41,10 @@
- + - @T["This key serves to differentiate the current form's location. Leave blank if the workflow handles a single form event."] + @T["This key name is used to store and then retrieve the current form's location. Leave blank if the workflow doesn't handle any form or a single one."]