diff --git a/src/Umbraco.Core/Configuration/GlobalSettings.cs b/src/Umbraco.Core/Configuration/GlobalSettings.cs index 395502d1b2..2ac8e7d2ac 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/GlobalSettings.cs @@ -35,7 +35,7 @@ namespace Umbraco.Core.Configuration private static Version _version; private static readonly object Locker = new object(); //make this volatile so that we can ensure thread safety with a double check lock - private static volatile string _reservedUrlsCache; + private static volatile string _reservedUrlsCache; private static string _reservedPathsCache; private static HashSet _reservedList = new HashSet(); private static string _reservedPaths; @@ -190,7 +190,7 @@ namespace Umbraco.Core.Configuration /// This will return the MVC area that we will route all custom routes through like surface controllers, etc... /// We will use the 'Path' (default ~/umbraco) to create it but since it cannot contain '/' and people may specify a path of ~/asdf/asdf/admin /// we will convert the '/' to '-' and use that as the path. its a bit lame but will work. - /// + /// /// We also make sure that the virtual directory (SystemDirectories.Root) is stripped off first, otherwise we'd end up with something /// like "MyVirtualDirectory-Umbraco" instead of just "Umbraco". /// @@ -205,7 +205,7 @@ namespace Umbraco.Core.Configuration var path = Path; if (path.StartsWith(SystemDirectories.Root)) // beware of TrimStart, see U4-2518 path = path.Substring(SystemDirectories.Root.Length); - return path.TrimStart('~').TrimStart('/').Replace('/', '-').Trim().ToLower(); + return path.TrimStart('~').TrimStart('/').Replace('/', '-').Trim().ToLower(); } } @@ -312,7 +312,7 @@ namespace Umbraco.Core.Configuration SetMembershipProvidersLegacyEncoding(UmbracoConfig.For.UmbracoSettings().Providers.DefaultBackOfficeUserProvider, value); } } - + /// /// Saves a setting into the configuration file. /// @@ -503,7 +503,7 @@ namespace Umbraco.Core.Configuration } /// - /// Returns a string value to determine if umbraco should skip version-checking. + /// Returns the number of days that should take place between version checks. /// /// The version check period in days (0 = never). public static int VersionCheckPeriod diff --git a/src/Umbraco.Core/StringExtensions.cs b/src/Umbraco.Core/StringExtensions.cs index 141a8fe28b..ce9ac77712 100644 --- a/src/Umbraco.Core/StringExtensions.cs +++ b/src/Umbraco.Core/StringExtensions.cs @@ -8,14 +8,12 @@ using System.Linq; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; -using System.Web; -using System.Xml; -using Newtonsoft.Json; -using Umbraco.Core.Configuration; using System.Web.Security; -using Umbraco.Core.Strings; +using Newtonsoft.Json; using Umbraco.Core.CodeAnnotations; +using Umbraco.Core.Configuration; using Umbraco.Core.IO; +using Umbraco.Core.Strings; namespace Umbraco.Core { @@ -472,13 +470,13 @@ namespace Umbraco.Core return ch.ToString(CultureInfo.InvariantCulture) == ch.ToString(CultureInfo.InvariantCulture).ToUpperInvariant(); } - /// Is null or white space. - /// The str. - /// The is null or white space. - public static bool IsNullOrWhiteSpace(this string str) - { - return (str == null) || (str.Trim().Length == 0); - } + /// Indicates whether a specified string is null, empty, or + /// consists only of white-space characters. + /// The value to check. + /// Returns if the value is null, + /// empty, or consists only of white-space characters, otherwise + /// returns . + public static bool IsNullOrWhiteSpace(this string value) => string.IsNullOrWhiteSpace(value); public static string IfNullOrWhiteSpace(this string str, string defaultValue) { diff --git a/src/Umbraco.Tests/Strings/StringExtensionsTests.cs b/src/Umbraco.Tests/Strings/StringExtensionsTests.cs index f5f69e37cd..836930c48a 100644 --- a/src/Umbraco.Tests/Strings/StringExtensionsTests.cs +++ b/src/Umbraco.Tests/Strings/StringExtensionsTests.cs @@ -161,6 +161,29 @@ namespace Umbraco.Tests.Strings Assert.AreEqual(expected, output); } + [TestCase("", true)] + [TestCase(" ", true)] + [TestCase("\r\n\r\n", true)] + [TestCase("\r\n", true)] + [TestCase(@" + Hello + ", false)] + [TestCase(null, true)] + [TestCase("a", false)] + [TestCase("abc", false)] + [TestCase("abc ", false)] + [TestCase(" abc", false)] + [TestCase(" abc ", false)] + public void IsNullOrWhiteSpace(string value, bool expected) + { + // Act + bool result = value.IsNullOrWhiteSpace(); + + // Assert + Assert.AreEqual(expected, result); + } + + // FORMAT STRINGS // note: here we just ensure that the proper helper gets called properly