diff --git a/src/Umbraco.Core/StringExtensions.cs b/src/Umbraco.Core/StringExtensions.cs
index 141a8fe28b..e4f313795b 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,16 @@ 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);
+ //{
+ // return (value == null) || (value.Trim().Length == 0);
+ //}
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