Web.Routing - sanitize DomainAndUri

This commit is contained in:
Stephan
2013-02-26 16:52:43 -01:00
parent eba5fc84c0
commit 7da60e9937
3 changed files with 18 additions and 18 deletions

View File

@@ -13,25 +13,25 @@ namespace Umbraco.Web.Routing
internal class DomainAndUri
{
/// <summary>
/// Initializes a new instance of the <see cref="DomainAndUri"/> class with a Domain and a Uri.
/// Initializes a new instance of the <see cref="DomainAndUri"/> class with a Domain and a uri scheme.
/// </summary>
/// <param name="domain">The Domain.</param>
/// <param name="uri">The Uri.</param>
public DomainAndUri(Domain domain, Uri uri)
/// <param name="domain">The domain.</param>
/// <param name="scheme">The uri scheme.</param>
public DomainAndUri(Domain domain, string scheme)
{
Domain = domain;
Uri = uri;
Uri = new Uri(UriUtility.TrimPathEndSlash(UriUtility.StartWithScheme(domain.Name, scheme)));
}
/// <summary>
/// Gets or sets the Umbraco domain.
/// </summary>
public Domain Domain { get; internal set; }
public Domain Domain { get; private set; }
/// <summary>
/// Gets or sets the normalized uri of the domain.
/// </summary>
public Uri Uri { get; internal set; }
public Uri Uri { get; private set; }
/// <summary>
/// Gets a string that represents the <see cref="DomainAndUri"/> instance.

View File

@@ -50,9 +50,8 @@ namespace Umbraco.Web.Routing
var domainsAndUris = domains
.Where(d => !d.IsWildcard)
.Select(SanitizeForBackwardCompatibility)
.Select(d => new { Domain = d, UriString = UriUtility.EndPathWithSlash(UriUtility.StartWithScheme(d.Name, scheme)) })
.OrderByDescending(t => t.UriString)
.Select(t => new DomainAndUri(t.Domain, new Uri(t.UriString)))
.Select(d => new DomainAndUri(d, scheme))
.OrderByDescending(d => d.Uri.ToString())
.ToArray();
if (!domainsAndUris.Any())
@@ -70,7 +69,7 @@ namespace Umbraco.Web.Routing
// assume only one can match the hint (is that OK?)
var hintWithSlash = current.EndPathWithSlash();
domainAndUri = domainsAndUris
.FirstOrDefault(t => t.Uri.IsBaseOf(hintWithSlash));
.FirstOrDefault(d => d.Uri.EndPathWithSlash().IsBaseOf(hintWithSlash));
// if none matches, then try to run the filter to sort them out
if (domainAndUri == null && filter != null)
{
@@ -82,8 +81,6 @@ namespace Umbraco.Web.Routing
}
}
if (domainAndUri != null)
domainAndUri.Uri = domainAndUri.Uri.TrimPathEndSlash();
return domainAndUri;
}
@@ -99,9 +96,8 @@ namespace Umbraco.Web.Routing
var domainsAndUris = domains
.Where(d => !d.IsWildcard)
.Select(SanitizeForBackwardCompatibility)
.Select(d => new { Domain = d, UriString = UriUtility.TrimPathEndSlash(UriUtility.StartWithScheme(d.Name, scheme)) })
.OrderByDescending(t => t.UriString)
.Select(t => new DomainAndUri(t.Domain, new Uri(t.UriString)));
.Select(d => new DomainAndUri(d, scheme))
.OrderByDescending(d => d.Uri.ToString());
return domainsAndUris;
}

View File

@@ -84,7 +84,11 @@ namespace Umbraco.Web
var umbracoContext = new UmbracoContext(httpContext, applicationContext);
// create the nice urls provider
var niceUrls = new NiceUrlProvider(PublishedContentStoreResolver.Current.PublishedContentStore, umbracoContext);
// there's one per request because there are some behavior parameters that can be changed
var urlProvider = new UrlProvider(
umbracoContext,
PublishedContentStoreResolver.Current.PublishedContentStore,
UrlProviderResolver.Current.Providers);
// create the RoutingContext, and assign
var routingContext = new RoutingContext(
@@ -92,7 +96,7 @@ namespace Umbraco.Web
ContentFinderResolver.Current.Finders,
ContentLastChanceFinderResolver.Current.Finder,
PublishedContentStoreResolver.Current.PublishedContentStore,
niceUrls,
urlProvider,
RoutesCacheResolver.Current.RoutesCache);
//assign the routing context back