From ddfd9eeb185f3837068d0e77dc62bb5dd8b3f3c5 Mon Sep 17 00:00:00 2001 From: Stephan Date: Fri, 14 Jun 2013 00:30:02 +0200 Subject: [PATCH] Core.UriExtensions - refactor + issue with IsClientSideRequest --- src/Umbraco.Core/UriExtensions.cs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Umbraco.Core/UriExtensions.cs b/src/Umbraco.Core/UriExtensions.cs index 6ecb8d67e8..9de8cf4867 100644 --- a/src/Umbraco.Core/UriExtensions.cs +++ b/src/Umbraco.Core/UriExtensions.cs @@ -1,7 +1,6 @@ using System; using System.IO; using System.Linq; -using System.Text; using Umbraco.Core.Configuration; using Umbraco.Core.IO; @@ -57,6 +56,7 @@ namespace Umbraco.Core /// internal static bool IsClientSideRequest(this Uri url) { + // fixme - but really, is this OK? we should accept either no url, or .aspx, and everything else is out var toIgnore = new[] { ".js", ".css", ".ico", ".png", ".jpg", ".jpeg", ".gif", ".html", ".svg" }; return toIgnore.Any(x => Path.GetExtension(url.LocalPath).InvariantEquals(x)); } @@ -70,7 +70,7 @@ namespace Umbraco.Core /// Everything else remains unchanged, except for the fragment which is removed. public static Uri Rewrite(this Uri uri, string path) { - if (!path.StartsWith("/")) + if (path.StartsWith("/") == false) throw new ArgumentException("Path must start with a slash.", "path"); return uri.IsAbsoluteUri @@ -88,9 +88,9 @@ namespace Umbraco.Core /// Everything else remains unchanged, except for the fragment which is removed. public static Uri Rewrite(this Uri uri, string path, string query) { - if (!path.StartsWith("/")) + if (path.StartsWith("/") == false) throw new ArgumentException("Path must start with a slash.", "path"); - if (query.Length > 0 && !query.StartsWith("?")) + if (query.Length > 0 && query.StartsWith("?") == false) throw new ArgumentException("Query must start with a question mark.", "query"); if (query == "?") query = ""; @@ -153,15 +153,14 @@ namespace Umbraco.Core var path = uri.GetSafeAbsolutePath(); if (uri.IsAbsoluteUri) { - if (path != "/" && !path.EndsWith("/")) + if (path != "/" && path.EndsWith("/") == false) uri = new Uri(uri.GetLeftPart(UriPartial.Authority) + path + "/" + uri.Query); return uri; } - else - { - if (path != "/" && !path.EndsWith("/")) - uri = new Uri(path + "/" + uri.Query, UriKind.Relative); - } + + if (path != "/" && path.EndsWith("/") == false) + uri = new Uri(path + "/" + uri.Query, UriKind.Relative); + return uri; }