Framework: Fixing that TemplateFilterForPart should be able to identify an editor group name with spaces (#7683)

This commit is contained in:
Lombiq
2018-09-25 18:58:28 +02:00
committed by Benedek Farkas
parent cd301e0f94
commit 55485cb465
2 changed files with 16 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
using System;
using Orchard.Utility.Extensions;
namespace Orchard.ContentManagement.Handlers {
public class TemplateFilterForPart<TPart> : TemplateFilterBase<ContentPart> where TPart : ContentPart, new() {
@@ -35,7 +36,7 @@ namespace Orchard.ContentManagement.Handlers {
}
protected override void BuildEditorShape(BuildEditorContext context, ContentPart part) {
if (!string.Equals(_groupId, context.GroupId, StringComparison.OrdinalIgnoreCase))
if (!_groupId.SafeNameEquals(context.GroupId, StringComparison.OrdinalIgnoreCase))
return;
var templatePart = part.As<TPart>();
@@ -44,7 +45,7 @@ namespace Orchard.ContentManagement.Handlers {
}
protected override void UpdateEditorShape(UpdateEditorContext context, ContentPart part) {
if (!string.Equals(_groupId, context.GroupId, StringComparison.OrdinalIgnoreCase))
if (!_groupId.SafeNameEquals(context.GroupId, StringComparison.OrdinalIgnoreCase))
return;
var templatePart = part.As<TPart>();

View File

@@ -190,6 +190,18 @@ namespace Orchard.Utility.Extensions {
return name;
}
/// <summary>
/// Compares two strings after converting them to valid technical names.
/// </summary>
public static bool SafeNameEquals(this string name, string otherName) =>
name.ToSafeName() == otherName.ToSafeName();
/// <summary>
/// Compares two strings using a string comparison option after converting them to valid technical names.
/// </summary>
public static bool SafeNameEquals(this string name, string otherName, StringComparison comparisonType) =>
string.Equals(name.ToSafeName(), otherName.ToSafeName(), comparisonType);
/// <summary>
/// Generates a valid Html name.
/// </summary>