Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add null string support in StringUtils #3826

Merged
merged 3 commits into from
Apr 29, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libraries/Microsoft.Bot.Builder/StringUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static class StringUtils
/// <returns>string length + ...</returns>
public static string Ellipsis(string text, int length)
{
text = text ?? string.Empty;
if (text.Length <= length)
{
return text;
Expand All @@ -32,6 +33,7 @@ public static string Ellipsis(string text, int length)
/// <returns>string which is unique SHA256 hash.</returns>
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));
Expand All @@ -47,6 +49,7 @@ public static string Hash(string text)
/// <returns>prefix up to length + ... + uniquehash(text).</returns>
public static string EllipsisHash(string text, int length)
{
text = text ?? string.Empty;
if (text.Length <= length)
{
return text;
Expand Down