From 1923b68594c8c9d2a37aa86d9ee81734abc088a2 Mon Sep 17 00:00:00 2001 From: yawka Date: Thu, 7 Nov 2013 12:36:35 +0200 Subject: [PATCH 1/4] Fix 2034, add check for whitespaces --- src/Umbraco.Core/IO/IOHelper.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Core/IO/IOHelper.cs b/src/Umbraco.Core/IO/IOHelper.cs index 22dc0814d5..bb23cde56e 100644 --- a/src/Umbraco.Core/IO/IOHelper.cs +++ b/src/Umbraco.Core/IO/IOHelper.cs @@ -43,7 +43,10 @@ namespace Umbraco.Core.IO //Replaces tildes with the root dir public static string ResolveUrl(string virtualPath) { - if (virtualPath.StartsWith("~")) + if (string.IsNullOrWhiteSpace(virtualPath)) + return string.Empty; + + if (virtualPath.StartsWith("~")) return virtualPath.Replace("~", SystemDirectories.Root).Replace("//", "/"); else if (Uri.IsWellFormedUriString(virtualPath, UriKind.Absolute)) return virtualPath; From 0debf9c34faa05201b52577755a97a229c8a61be Mon Sep 17 00:00:00 2001 From: yawka Date: Thu, 7 Nov 2013 19:05:50 +0200 Subject: [PATCH 2/4] Add check is path is whitespace --- src/Umbraco.Core/Configuration/GlobalSettings.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Umbraco.Core/Configuration/GlobalSettings.cs b/src/Umbraco.Core/Configuration/GlobalSettings.cs index 4526ece5f3..3dbc99fba9 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/GlobalSettings.cs @@ -704,6 +704,8 @@ namespace Umbraco.Core.Configuration StartsWithContainer _newReservedList = new StartsWithContainer(); foreach (string reservedUrl in _reservedUrlsCache.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)) { + if (string.IsNullOrWhiteSpace(reservedUrl)) + continue; //resolves the url to support tilde chars string reservedUrlTrimmed = IOHelper.ResolveUrl(reservedUrl).Trim().ToLower(); if (reservedUrlTrimmed.Length > 0) @@ -713,6 +715,8 @@ namespace Umbraco.Core.Configuration foreach (string reservedPath in _reservedPathsCache.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)) { bool trimEnd = !reservedPath.EndsWith("/"); + if (string.IsNullOrWhiteSpace(reservedPath)) + continue; //resolves the url to support tilde chars string reservedPathTrimmed = IOHelper.ResolveUrl(reservedPath).Trim().ToLower(); From 59391f58ec7a8d55fe21dd861b9cbcac5522121c Mon Sep 17 00:00:00 2001 From: yawka Date: Thu, 7 Nov 2013 19:06:25 +0200 Subject: [PATCH 3/4] Remove previous fix, and move it to IsReservedPathOrUrl --- src/Umbraco.Core/IO/IOHelper.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Umbraco.Core/IO/IOHelper.cs b/src/Umbraco.Core/IO/IOHelper.cs index bb23cde56e..9f917f18a7 100644 --- a/src/Umbraco.Core/IO/IOHelper.cs +++ b/src/Umbraco.Core/IO/IOHelper.cs @@ -43,9 +43,6 @@ namespace Umbraco.Core.IO //Replaces tildes with the root dir public static string ResolveUrl(string virtualPath) { - if (string.IsNullOrWhiteSpace(virtualPath)) - return string.Empty; - if (virtualPath.StartsWith("~")) return virtualPath.Replace("~", SystemDirectories.Root).Replace("//", "/"); else if (Uri.IsWellFormedUriString(virtualPath, UriKind.Absolute)) From aacb86bf92da5493276fcdeca84e43ff1c428205 Mon Sep 17 00:00:00 2001 From: yawka Date: Thu, 7 Nov 2013 19:09:50 +0200 Subject: [PATCH 4/4] Add trim to all urls --- src/Umbraco.Core/Configuration/GlobalSettings.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Core/Configuration/GlobalSettings.cs b/src/Umbraco.Core/Configuration/GlobalSettings.cs index 3dbc99fba9..d3c1fcb2ae 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/GlobalSettings.cs @@ -706,8 +706,10 @@ namespace Umbraco.Core.Configuration { if (string.IsNullOrWhiteSpace(reservedUrl)) continue; + + //resolves the url to support tilde chars - string reservedUrlTrimmed = IOHelper.ResolveUrl(reservedUrl).Trim().ToLower(); + string reservedUrlTrimmed = IOHelper.ResolveUrl(reservedUrl.Trim()).Trim().ToLower(); if (reservedUrlTrimmed.Length > 0) _newReservedList.Add(reservedUrlTrimmed); } @@ -717,8 +719,9 @@ namespace Umbraco.Core.Configuration bool trimEnd = !reservedPath.EndsWith("/"); if (string.IsNullOrWhiteSpace(reservedPath)) continue; + //resolves the url to support tilde chars - string reservedPathTrimmed = IOHelper.ResolveUrl(reservedPath).Trim().ToLower(); + string reservedPathTrimmed = IOHelper.ResolveUrl(reservedPath.Trim()).Trim().ToLower(); if (reservedPathTrimmed.Length > 0) _newReservedList.Add(reservedPathTrimmed + (reservedPathTrimmed.EndsWith("/") ? "" : "/"));