From 8273e61cf595218c095e95ad2a817d3a55fb60e6 Mon Sep 17 00:00:00 2001 From: hond Date: Wed, 29 Apr 2020 14:38:13 +0800 Subject: [PATCH 1/3] add null string support in StringUtil --- libraries/Microsoft.Bot.Builder/StringUtils.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/Microsoft.Bot.Builder/StringUtils.cs b/libraries/Microsoft.Bot.Builder/StringUtils.cs index 67ba1a62ea..13e1339243 100644 --- a/libraries/Microsoft.Bot.Builder/StringUtils.cs +++ b/libraries/Microsoft.Bot.Builder/StringUtils.cs @@ -17,6 +17,7 @@ public static class StringUtils /// string length + ... public static string Ellipsis(string text, int length) { + text = text ?? string.Empty; if (text.Length <= length) { return text; @@ -32,6 +33,7 @@ public static string Ellipsis(string text, int length) /// string which is unique SHA256 hash. public static string Hash(string text) { + text = text ?? string.Empty; using (var sha256Hash = SHA256.Create()) { byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(text)); @@ -47,6 +49,7 @@ public static string Hash(string text) /// prefix up to length + ... + uniquehash(text). public static string EllipsisHash(string text, int length) { + text = text ?? string.Empty; if (text.Length <= length) { return text; From 4d887d30d1b2e4c23b009629fd34bbe90538efd9 Mon Sep 17 00:00:00 2001 From: Tom Laird-McConnell Date: Wed, 29 Apr 2020 07:57:29 -0700 Subject: [PATCH 2/3] change Hash() to throw for null --- libraries/Microsoft.Bot.Builder/StringUtils.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Microsoft.Bot.Builder/StringUtils.cs b/libraries/Microsoft.Bot.Builder/StringUtils.cs index 13e1339243..d2191848b8 100644 --- a/libraries/Microsoft.Bot.Builder/StringUtils.cs +++ b/libraries/Microsoft.Bot.Builder/StringUtils.cs @@ -33,7 +33,7 @@ public static string Ellipsis(string text, int length) /// string which is unique SHA256 hash. public static string Hash(string text) { - text = text ?? string.Empty; + text = text ?? new ArgumentNullException(nameof(text)); using (var sha256Hash = SHA256.Create()) { byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(text)); From ba7c3beb6443acdbc389e5e71c8a4a5ea5236548 Mon Sep 17 00:00:00 2001 From: Tom Laird-McConnell Date: Wed, 29 Apr 2020 08:15:27 -0700 Subject: [PATCH 3/3] remove null check for Hash() it should throw if string is null --- libraries/Microsoft.Bot.Builder/StringUtils.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/Microsoft.Bot.Builder/StringUtils.cs b/libraries/Microsoft.Bot.Builder/StringUtils.cs index d2191848b8..175ca3bc91 100644 --- a/libraries/Microsoft.Bot.Builder/StringUtils.cs +++ b/libraries/Microsoft.Bot.Builder/StringUtils.cs @@ -33,7 +33,6 @@ public static string Ellipsis(string text, int length) /// string which is unique SHA256 hash. public static string Hash(string text) { - text = text ?? new ArgumentNullException(nameof(text)); using (var sha256Hash = SHA256.Create()) { byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(text));