From 621e07cd6c2eebe9ddb75f84e7616cebcb8c27ef Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Fri, 8 Nov 2024 16:31:57 -0800 Subject: [PATCH] Fix functional tests --- .../DashboardPartContentTypeDefinitionHandler.cs | 4 ++-- .../Utilities/StringExtensions.cs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Services/DashboardPartContentTypeDefinitionHandler.cs b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Services/DashboardPartContentTypeDefinitionHandler.cs index eeb80579507..85921628eb2 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Services/DashboardPartContentTypeDefinitionHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Services/DashboardPartContentTypeDefinitionHandler.cs @@ -15,7 +15,7 @@ public sealed class DashboardPartContentTypeDefinitionHandler : IContentDefiniti /// public void ContentTypeBuilding(ContentTypeBuildingContext context) { - if (!context.Record.Settings.TryGetPropertyValue(nameof(ContentTypeSettings), out var node)) + if (context?.Record?.Settings is null || !context.Record.Settings.TryGetPropertyValue(nameof(ContentTypeSettings), out var node)) { return; } @@ -52,7 +52,7 @@ public void ContentTypeBuilding(ContentTypeBuildingContext context) /// public void ContentTypePartBuilding(ContentTypePartBuildingContext context) { - if (!context.Record.PartName.EqualsOrdinalIgnoreCase(nameof(DashboardPart))) + if (context?.Record?.Settings is null || !context.Record.PartName.EqualsOrdinalIgnoreCase(nameof(DashboardPart))) { return; } diff --git a/src/OrchardCore/OrchardCore.DisplayManagement.Abstractions/Utilities/StringExtensions.cs b/src/OrchardCore/OrchardCore.DisplayManagement.Abstractions/Utilities/StringExtensions.cs index 78f97ebc282..f0d1f2c79ff 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement.Abstractions/Utilities/StringExtensions.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement.Abstractions/Utilities/StringExtensions.cs @@ -1,7 +1,11 @@ +using System.Buffers; + namespace OrchardCore.DisplayManagement.Utilities; public static class StringExtensions { + private static readonly SearchValues AlternateChars = SearchValues.Create("-."); + /// /// Encodes dashed and dots so that they don't conflict in filenames. /// @@ -9,6 +13,16 @@ public static class StringExtensions /// public static string EncodeAlternateElement(this string alternateElement) { + if (string.IsNullOrEmpty(alternateElement)) + { + return ""; + } + + if (!alternateElement.AsSpan().ContainsAny(AlternateChars)) + { + return alternateElement; + } + return alternateElement.Replace("-", "__").Replace('.', '_'); } }