Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix functional tests #16980

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class DashboardPartContentTypeDefinitionHandler : IContentDefiniti
/// </summary>
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;
}
Expand Down Expand Up @@ -52,7 +52,7 @@ public void ContentTypeBuilding(ContentTypeBuildingContext context)
/// </summary>
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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
using System.Buffers;

namespace OrchardCore.DisplayManagement.Utilities;

public static class StringExtensions
{
private static readonly SearchValues<char> AlternateChars = SearchValues.Create("-.");

/// <summary>
/// Encodes dashed and dots so that they don't conflict in filenames.
/// </summary>
/// <param name="alternateElement"></param>
/// <returns></returns>
public static string EncodeAlternateElement(this string alternateElement)
{
if (string.IsNullOrEmpty(alternateElement))
{
return "";
}

if (!alternateElement.AsSpan().ContainsAny(AlternateChars))
{
return alternateElement;
}
Comment on lines +21 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this fix an exception? Or is this condition just for perf?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it's unrelated, just trying to squeeze some perf. Also an opportunity to raise awareness about SeachValues.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's good, TIL.


return alternateElement.Replace("-", "__").Replace('.', '_');
}
}