Fix domain for invariant content nodes (#12405)

Co-authored-by: Elitsa Marinovska <elm@umbraco.dk>
This commit is contained in:
Mole
2022-05-18 15:22:51 +02:00
committed by Nikolaj
parent a3692b887a
commit e40049dcf1
2 changed files with 11 additions and 12 deletions

View File

@@ -164,10 +164,10 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
// 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())
@@ -178,13 +178,13 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
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
@@ -204,7 +204,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
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;
}

View File

@@ -1,5 +1,3 @@
using System;
using System.Linq;
using Umbraco.Cms.Core.PublishedCache;
namespace Umbraco.Cms.Infrastructure.PublishedCache
@@ -11,7 +9,8 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
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);
}
}
}