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 ContentType.Alias matching in PublishedContentExtensions and PublishedElementExtensions #6577

Merged
merged 6 commits into from
Oct 15, 2019
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
24 changes: 12 additions & 12 deletions src/Umbraco.Web/PublishedContentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static class PublishedContentExtensions
/// <returns>A value indicating whether the content is of a content type composed of a content type identified by the alias.</returns>
public static bool IsComposedOf(this IPublishedContent content, string alias)
{
return content.ContentType.CompositionAliases.Contains(alias);
return content.ContentType.CompositionAliases.InvariantContains(alias);
}

#endregion
Expand Down Expand Up @@ -421,7 +421,7 @@ public static IEnumerable<IPublishedContent> Ancestors(this IPublishedContent co
/// <remarks>Does not consider the content itself. Returns all ancestors, of the specified content type.</remarks>
public static IEnumerable<IPublishedContent> Ancestors(this IPublishedContent content, string contentTypeAlias)
{
return content.AncestorsOrSelf(false, n => n.ContentType.Alias == contentTypeAlias);
return content.AncestorsOrSelf(false, n => n.ContentType.Alias.InvariantEquals(contentTypeAlias));
}

/// <summary>
Expand Down Expand Up @@ -486,7 +486,7 @@ public static IEnumerable<IPublishedContent> AncestorsOrSelf(this IPublishedCont
/// <remarks>May or may not begin with the content itself, depending on its content type.</remarks>
public static IEnumerable<IPublishedContent> AncestorsOrSelf(this IPublishedContent content, string contentTypeAlias)
{
return content.AncestorsOrSelf(true, n => n.ContentType.Alias == contentTypeAlias);
return content.AncestorsOrSelf(true, n => n.ContentType.Alias.InvariantEquals(contentTypeAlias));
}

/// <summary>
Expand Down Expand Up @@ -549,7 +549,7 @@ public static IPublishedContent Ancestor(this IPublishedContent content, int max
/// <remarks>Does not consider the content itself. May return <c>null</c>.</remarks>
public static IPublishedContent Ancestor(this IPublishedContent content, string contentTypeAlias)
{
return content.EnumerateAncestors(false).FirstOrDefault(x => x.ContentType.Alias == contentTypeAlias);
return content.EnumerateAncestors(false).FirstOrDefault(x => x.ContentType.Alias.InvariantEquals(contentTypeAlias));
}

/// <summary>
Expand Down Expand Up @@ -612,7 +612,7 @@ public static IPublishedContent AncestorOrSelf(this IPublishedContent content, i
/// <remarks>May or may not return the content itself depending on its content type. May return <c>null</c>.</remarks>
public static IPublishedContent AncestorOrSelf(this IPublishedContent content, string contentTypeAlias)
{
return content.EnumerateAncestors(true).FirstOrDefault(x => x.ContentType.Alias == contentTypeAlias);
return content.EnumerateAncestors(true).FirstOrDefault(x => x.ContentType.Alias.InvariantEquals(contentTypeAlias));
}

/// <summary>
Expand Down Expand Up @@ -727,7 +727,7 @@ public static IEnumerable<IPublishedContent> Descendants(this IPublishedContent

public static IEnumerable<IPublishedContent> DescendantsOfType(this IPublishedContent content, string contentTypeAlias, string culture = null)
{
return content.DescendantsOrSelf(false, p => p.ContentType.Alias == contentTypeAlias, culture);
return content.DescendantsOrSelf(false, p => p.ContentType.Alias.InvariantEquals(contentTypeAlias), culture);
}

public static IEnumerable<T> Descendants<T>(this IPublishedContent content, string culture = null)
Expand All @@ -754,7 +754,7 @@ public static IEnumerable<IPublishedContent> DescendantsOrSelf(this IPublishedCo

public static IEnumerable<IPublishedContent> DescendantsOrSelfOfType(this IPublishedContent content, string contentTypeAlias, string culture = null)
{
return content.DescendantsOrSelf(true, p => p.ContentType.Alias == contentTypeAlias, culture);
return content.DescendantsOrSelf(true, p => p.ContentType.Alias.InvariantEquals(contentTypeAlias), culture);
}

public static IEnumerable<T> DescendantsOrSelf<T>(this IPublishedContent content, string culture = null)
Expand All @@ -781,7 +781,7 @@ public static IPublishedContent Descendant(this IPublishedContent content, int l

public static IPublishedContent DescendantOfType(this IPublishedContent content, string contentTypeAlias, string culture = null)
{
return content.EnumerateDescendants(false, culture).FirstOrDefault(x => x.ContentType.Alias == contentTypeAlias);
return content.EnumerateDescendants(false, culture).FirstOrDefault(x => x.ContentType.Alias.InvariantEquals(contentTypeAlias));
}

public static T Descendant<T>(this IPublishedContent content, string culture = null)
Expand All @@ -808,7 +808,7 @@ public static IPublishedContent DescendantOrSelf(this IPublishedContent content,

public static IPublishedContent DescendantOrSelfOfType(this IPublishedContent content, string contentTypeAlias, string culture = null)
{
return content.EnumerateDescendants(true, culture).FirstOrDefault(x => x.ContentType.Alias == contentTypeAlias);
return content.EnumerateDescendants(true, culture).FirstOrDefault(x => x.ContentType.Alias.InvariantEquals(contentTypeAlias));
}

public static T DescendantOrSelf<T>(this IPublishedContent content, string culture = null)
Expand Down Expand Up @@ -892,7 +892,7 @@ public static IEnumerable<IPublishedContent> Children(this IPublishedContent con
/// <returns>The children of the content, of any of the specified types.</returns>
public static IEnumerable<IPublishedContent> ChildrenOfType(this IPublishedContent content, string contentTypeAlias, string culture = null)
{
return content.Children(x => contentTypeAlias.InvariantContains(x.ContentType.Alias), culture);
return content.Children(x => x.ContentType.Alias.InvariantEquals(contentTypeAlias), culture);
}

/// <summary>
Expand Down Expand Up @@ -973,7 +973,7 @@ private static DataTable GenerateDataTable(IPublishedContent content, ServiceCon
? content.Children(culture).Any()
? content.Children(culture).ElementAt(0)
: null
: content.Children(culture).FirstOrDefault(x => x.ContentType.Alias == contentTypeAliasFilter);
: content.Children(culture).FirstOrDefault(x => x.ContentType.Alias.InvariantEquals(contentTypeAliasFilter));
if (firstNode == null)
return new DataTable(); //no children found

Expand All @@ -993,7 +993,7 @@ private static DataTable GenerateDataTable(IPublishedContent content, ServiceCon
{
if (contentTypeAliasFilter.IsNullOrWhiteSpace() == false)
{
if (n.ContentType.Alias != contentTypeAliasFilter)
if (n.ContentType.Alias.InvariantEquals(contentTypeAliasFilter) == false)
continue; //skip this one, it doesn't match the filter
}

Expand Down
7 changes: 4 additions & 3 deletions src/Umbraco.Web/PublishedElementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static class PublishedElementExtensions
/// <returns>A value indicating whether the content is of a content type composed of a content type identified by the alias.</returns>
public static bool IsComposedOf(this IPublishedElement content, string alias)
{
return content.ContentType.CompositionAliases.Contains(alias);
return content.ContentType.CompositionAliases.InvariantContains(alias);
}

#endregion
Expand Down Expand Up @@ -165,8 +165,9 @@ public static IndexedArrayItem<TContent>[] ToIndexedArray<TContent>(this IEnumer
public static IEnumerable<T> OfTypes<T>(this IEnumerable<T> contents, params string[] types)
where T : IPublishedElement
{
types = types.Select(x => x.ToLowerInvariant()).ToArray();
return contents.Where(x => types.Contains(x.ContentType.Alias.ToLowerInvariant()));
if (types == null || types.Length == 0) return Enumerable.Empty<T>();

return contents.Where(x => types.InvariantContains(x.ContentType.Alias));
rbottema marked this conversation as resolved.
Show resolved Hide resolved
}

#endregion
Expand Down