Skip to content

Commit

Permalink
Fix domain for invariant content nodes (#12405)
Browse files Browse the repository at this point in the history
Co-authored-by: Elitsa Marinovska <elm@umbraco.dk>
  • Loading branch information
nikolajlauridsen and elit0451 committed May 18, 2022
1 parent a3692b8 commit e40049d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
18 changes: 9 additions & 9 deletions src/Umbraco.PublishedCache.NuCache/ContentCache.cs
Expand Up @@ -164,10 +164,10 @@ public class ContentCache : PublishedCacheBase, IPublishedContentCache, INavigab
// walk up from that node until we hit a node with a domain,
// or we reach the content root, collecting URLs in the way
var pathParts = new List<string>();
IPublishedContent? n = node;
var urlSegment = n.UrlSegment(_variationContextAccessor, culture);
var hasDomains = _domainCache.GetAssignedWithCulture(culture, n.Id);
while (hasDomains == false && n != null) // n is null at root
IPublishedContent? content = node;
var urlSegment = content.UrlSegment(_variationContextAccessor, culture);
var hasDomains = _domainCache.GetAssignedWithCulture(culture, content.Id);
while (hasDomains == false && content != null) // content is null at root
{
// no segment indicates this is not published when this is a variant
if (urlSegment.IsNullOrWhiteSpace())
Expand All @@ -178,13 +178,13 @@ public class ContentCache : PublishedCacheBase, IPublishedContentCache, INavigab
pathParts.Add(urlSegment!);

// move to parent node
n = n.Parent;
if (n != null)
content = content.Parent;
if (content != null)
{
urlSegment = n.UrlSegment(_variationContextAccessor, culture);
urlSegment = content.UrlSegment(_variationContextAccessor, culture);
}

hasDomains = n != null && _domainCache.GetAssignedWithCulture(culture, n.Id);
hasDomains = content != null && _domainCache.GetAssignedWithCulture(culture, content.Id);
}

// at this point this will be the urlSegment of the root, no segment indicates this is not published when this is a variant
Expand All @@ -204,7 +204,7 @@ public class ContentCache : PublishedCacheBase, IPublishedContentCache, INavigab
var path = "/" + string.Join("/", pathParts); // will be "/" or "/foo" or "/foo/bar" etc
//prefix the root node id containing the domain if it exists (this is a standard way of creating route paths)
//and is done so that we know the ID of the domain node for the path
var route = (n?.Id.ToString(CultureInfo.InvariantCulture) ?? "") + path;
var route = (content?.Id.ToString(CultureInfo.InvariantCulture) ?? "") + path;

return route;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Umbraco.PublishedCache.NuCache/DomainCacheExtensions.cs
@@ -1,5 +1,3 @@
using System;
using System.Linq;
using Umbraco.Cms.Core.PublishedCache;

namespace Umbraco.Cms.Infrastructure.PublishedCache
Expand All @@ -11,7 +9,8 @@ public static bool GetAssignedWithCulture(this IDomainCache domainCache, string?
var assigned = domainCache.GetAssigned(documentId, includeWildcards);

// It's super important that we always compare cultures with ignore case, since we can't be sure of the casing!
return culture is null ? assigned.Any() : assigned.Any(x => x.Culture?.Equals(culture, StringComparison.InvariantCultureIgnoreCase) ?? false);
// Comparing with string.IsNullOrEmpty since both empty string and null signifies invariant.
return string.IsNullOrEmpty(culture) ? assigned.Any() : assigned.Any(x => x.Culture?.Equals(culture, StringComparison.InvariantCultureIgnoreCase) ?? false);
}
}
}

0 comments on commit e40049d

Please sign in to comment.