From bec242a6a977fd163dae8b9e29dba63d74feb8bd Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 17 Mar 2020 16:20:36 +0100 Subject: [PATCH] Migration fixed and query parser improved. --- .../Comments/Commands/CommentTextCommand.cs | 2 -- .../Queries/Json/QueryParser.cs | 10 ++++++++++ .../Queries/JsonQueryConversionTests.cs | 20 +++++++++++++++++-- .../OldEvents/ContentUpdateProposed.cs | 3 +-- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/backend/src/Squidex.Domain.Apps.Entities/Comments/Commands/CommentTextCommand.cs b/backend/src/Squidex.Domain.Apps.Entities/Comments/Commands/CommentTextCommand.cs index 9565e5981..de9c66b09 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Comments/Commands/CommentTextCommand.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Comments/Commands/CommentTextCommand.cs @@ -5,8 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; - namespace Squidex.Domain.Apps.Entities.Comments.Commands { public abstract class CommentTextCommand : CommentsCommand diff --git a/backend/src/Squidex.Infrastructure/Queries/Json/QueryParser.cs b/backend/src/Squidex.Infrastructure/Queries/Json/QueryParser.cs index 4813e90de..cca0e0b06 100644 --- a/backend/src/Squidex.Infrastructure/Queries/Json/QueryParser.cs +++ b/backend/src/Squidex.Infrastructure/Queries/Json/QueryParser.cs @@ -20,8 +20,18 @@ namespace Squidex.Infrastructure.Queries.Json { public static ClrQuery Parse(this JsonSchema schema, string json, IJsonSerializer jsonSerializer) { + if (string.IsNullOrWhiteSpace(json)) + { + return new ClrQuery(); + } + var query = ParseFromJson(json, jsonSerializer); + if (query == null) + { + return new ClrQuery(); + } + var result = SimpleMapper.Map(query, new ClrQuery()); var errors = new List(); diff --git a/backend/tests/Squidex.Infrastructure.Tests/Queries/JsonQueryConversionTests.cs b/backend/tests/Squidex.Infrastructure.Tests/Queries/JsonQueryConversionTests.cs index b1a8b66fe..e2c9670e7 100644 --- a/backend/tests/Squidex.Infrastructure.Tests/Queries/JsonQueryConversionTests.cs +++ b/backend/tests/Squidex.Infrastructure.Tests/Queries/JsonQueryConversionTests.cs @@ -334,6 +334,22 @@ namespace Squidex.Infrastructure.Queries Assert.Throws(() => AssertQuery(json, null)); } + [Fact] + public void Should_not_throw_exception_when_parsing_null_string() + { + string? json = null; + + Assert.NotNull(schema.Parse(json!, JsonHelper.DefaultSerializer)); + } + + [Fact] + public void Should_not_throw_exception_when_parsing_null_json() + { + var json = "null"; + + Assert.NotNull(schema.Parse(json, JsonHelper.DefaultSerializer)); + } + private void AssertQuery(object json, string? expectedFilter) { var filter = ConvertQuery(json); @@ -374,9 +390,9 @@ namespace Squidex.Infrastructure.Queries { var json = JsonHelper.DefaultSerializer.Serialize(value, true); - var jsonFilter = schema.Parse(json, JsonHelper.DefaultSerializer); + var jsonQuery = schema.Parse(json, JsonHelper.DefaultSerializer); - return jsonFilter.ToString(); + return jsonQuery.ToString(); } } } diff --git a/backend/tools/Migrate_01/OldEvents/ContentUpdateProposed.cs b/backend/tools/Migrate_01/OldEvents/ContentUpdateProposed.cs index 9ad2445b4..6b9aaa3f3 100644 --- a/backend/tools/Migrate_01/OldEvents/ContentUpdateProposed.cs +++ b/backend/tools/Migrate_01/OldEvents/ContentUpdateProposed.cs @@ -7,7 +7,6 @@ using System; using Squidex.Domain.Apps.Core.Contents; -using Squidex.Domain.Apps.Events; using Squidex.Domain.Apps.Events.Contents; using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Migrations; @@ -17,7 +16,7 @@ namespace Migrate_01.OldEvents { [EventType(nameof(ContentUpdateProposed))] [Obsolete] - public sealed class ContentUpdateProposed : SquidexEvent, IMigrated + public sealed class ContentUpdateProposed : ContentEvent, IMigrated { public NamedContentData Data { get; set; }