From eba5fc84c075f918d83c104bed5f1579cc427d40 Mon Sep 17 00:00:00 2001 From: Stephan Date: Tue, 26 Feb 2013 16:52:43 -0100 Subject: [PATCH] Web.Routing - refactor wildcard domains --- src/Umbraco.Web/Routing/DomainHelper.cs | 15 ++++----------- src/umbraco.cms/businesslogic/web/Domain.cs | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/Umbraco.Web/Routing/DomainHelper.cs b/src/Umbraco.Web/Routing/DomainHelper.cs index 8d7c9c9972..5f30294499 100644 --- a/src/Umbraco.Web/Routing/DomainHelper.cs +++ b/src/Umbraco.Web/Routing/DomainHelper.cs @@ -11,13 +11,6 @@ namespace Umbraco.Web.Routing /// internal class DomainHelper { - private static bool IsWildcardDomain(Domain d) - { - // supporting null or whitespace for backward compatibility, - // although we should not allow ppl to create them anymore - return string.IsNullOrWhiteSpace(d.Name) || d.Name.StartsWith("*"); - } - private static Domain SanitizeForBackwardCompatibility(Domain d) { // this is a _really_ nasty one that should be removed in 6.x @@ -55,7 +48,7 @@ namespace Umbraco.Web.Routing // we need to order so example.com/foo matches before example.com/ var scheme = current == null ? Uri.UriSchemeHttp : current.Scheme; var domainsAndUris = domains - .Where(d => !IsWildcardDomain(d)) + .Where(d => !d.IsWildcard) .Select(SanitizeForBackwardCompatibility) .Select(d => new { Domain = d, UriString = UriUtility.EndPathWithSlash(UriUtility.StartWithScheme(d.Name, scheme)) }) .OrderByDescending(t => t.UriString) @@ -104,7 +97,7 @@ namespace Umbraco.Web.Routing { var scheme = current == null ? Uri.UriSchemeHttp : current.Scheme; var domainsAndUris = domains - .Where(d => !IsWildcardDomain(d)) + .Where(d => !d.IsWildcard) .Select(SanitizeForBackwardCompatibility) .Select(d => new { Domain = d, UriString = UriUtility.TrimPathEndSlash(UriUtility.StartWithScheme(d.Name, scheme)) }) .OrderByDescending(t => t.UriString) @@ -127,7 +120,7 @@ namespace Umbraco.Web.Routing .Reverse() .Select(int.Parse) .TakeWhile(id => id != stopNodeId) - .Any(id => domains.Any(d => d.RootNodeId == id && !IsWildcardDomain(d))); + .Any(id => domains.Any(d => d.RootNodeId == id && !d.IsWildcard)); } /// @@ -148,7 +141,7 @@ namespace Umbraco.Web.Routing .Skip(1) .Reverse() .TakeWhile(id => !rootNodeId.HasValue || id != rootNodeId) - .Select(nodeId => domains.FirstOrDefault(d => d.RootNodeId == nodeId && IsWildcardDomain(d))) + .Select(nodeId => domains.FirstOrDefault(d => d.RootNodeId == nodeId && d.IsWildcard)) .FirstOrDefault(domain => domain != null); } diff --git a/src/umbraco.cms/businesslogic/web/Domain.cs b/src/umbraco.cms/businesslogic/web/Domain.cs index 858bf65b99..2782a04b61 100644 --- a/src/umbraco.cms/businesslogic/web/Domain.cs +++ b/src/umbraco.cms/businesslogic/web/Domain.cs @@ -259,5 +259,23 @@ namespace umbraco.cms.businesslogic.web if (AfterDelete != null) AfterDelete(this, e); } + + #region Pipeline Refactoring + + // NOTE: the wildcard name thing should be managed by the Domain class + // internally but that would break too much backward compatibility, so + // we don't do it now. Will do it when the Domain class migrates to the + // new Core.Models API. + + /// + /// Gets a value indicating whether the domain is a wildcard domain. + /// + /// A value indicating whether the domain is a wildcard domain. + public bool IsWildcard + { + get { return string.IsNullOrWhiteSpace(Name) || Name.StartsWith("*"); } + } + + #endregion } } \ No newline at end of file