diff --git a/Lombiq.JsonEditor/Controllers/AdminController.cs b/Lombiq.JsonEditor/Controllers/AdminController.cs index 93235f7..55b7ab7 100644 --- a/Lombiq.JsonEditor/Controllers/AdminController.cs +++ b/Lombiq.JsonEditor/Controllers/AdminController.cs @@ -61,6 +61,8 @@ public AdminController( [AdminRoute("Contents/ContentItems/{contentItemId}/Edit/Json")] public async Task Edit(string contentItemId) { + if (!ModelState.IsValid) return BadRequest(ModelState); + if (string.IsNullOrWhiteSpace(contentItemId) || await _contentManager.GetAsync(contentItemId, VersionOptions.Latest) is not { } contentItem || !await CanEditAsync(contentItem)) @@ -90,6 +92,8 @@ public async Task EditPost( [Bind(Prefix = "submit.Publish")] string submitPublish, [Bind(Prefix = "submit.Save")] string submitSave) { + if (!ModelState.IsValid) return BadRequest(ModelState); + if (string.IsNullOrWhiteSpace(contentItemId) || string.IsNullOrWhiteSpace(json) || JsonConvert.DeserializeObject(json) is not { } contentItem) diff --git a/Lombiq.JsonEditor/Models/JsonEditorOptions.cs b/Lombiq.JsonEditor/Models/JsonEditorOptions.cs index 2a0df8d..885a682 100644 --- a/Lombiq.JsonEditor/Models/JsonEditorOptions.cs +++ b/Lombiq.JsonEditor/Models/JsonEditorOptions.cs @@ -45,7 +45,7 @@ public JsonEditorMode Mode set => ModeString = GetModeString(value); } - public IEnumerable Modes { get; set; } = new[] { "tree", "view", "form", "code", "text", "preview" }; + public IEnumerable Modes { get; set; } = ["tree", "view", "form", "code", "text", "preview"]; /// /// Gets or sets the JSON Schema to validate against. A JSON schema describes the structure that a JSON object must @@ -116,8 +116,8 @@ private static string GetModeString(JsonEditorMode mode) => public static JsonEditorOptions GetSample(IHtmlLocalizer localizer) => new() { - Templates = new[] - { + Templates = + [ new JsonEditorTemplate { Field = "aTechnicalNameThatHasToBeUnique", @@ -127,6 +127,6 @@ public static JsonEditorOptions GetSample(IHtmlLocalizer localizer) => .Value, Value = new { YourObject = "goes here" }, }, - }, + ], }; } diff --git a/Lombiq.JsonEditor/Services/JsonEditorContentSecurityPolicyProvider.cs b/Lombiq.JsonEditor/Services/JsonEditorContentSecurityPolicyProvider.cs index 27cd27d..722b071 100644 --- a/Lombiq.JsonEditor/Services/JsonEditorContentSecurityPolicyProvider.cs +++ b/Lombiq.JsonEditor/Services/JsonEditorContentSecurityPolicyProvider.cs @@ -1,4 +1,4 @@ -using Lombiq.HelpfulLibraries.AspNetCore.Security; +using Lombiq.HelpfulLibraries.AspNetCore.Security; using Lombiq.JsonEditor.Constants; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; @@ -18,7 +18,7 @@ public class JsonEditorContentSecurityPolicyProvider : ResourceManagerContentSec { protected override string ResourceType => "script"; protected override string ResourceName => ResourceNames.Library; - protected override IReadOnlyCollection DirectiveNameChain { get; } = new[] { WorkerSrc, ScriptSrc }; + protected override IReadOnlyCollection DirectiveNameChain { get; } = [WorkerSrc, ScriptSrc]; protected override string DirectiveValue => $"{Blob} {Data}"; protected override ValueTask ThenUpdateAsync(