From 8f3a4b98a585ad8f2834f2d932a4ef4754e28a36 Mon Sep 17 00:00:00 2001 From: Federico Maccaroni Date: Thu, 14 Jul 2022 17:33:30 -0300 Subject: [PATCH] EC-323 sanitize data on get first letters for avatar image creation (#1990) --- src/App/Controls/AvatarImageSource.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/App/Controls/AvatarImageSource.cs b/src/App/Controls/AvatarImageSource.cs index 4b5902618..38f3df31c 100644 --- a/src/App/Controls/AvatarImageSource.cs +++ b/src/App/Controls/AvatarImageSource.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Text; using System.Threading; using System.Threading.Tasks; using SkiaSharp; @@ -131,21 +132,23 @@ namespace Bit.App.Controls private string GetFirstLetters(string data, int charCount) { - var parts = data.Split(); + var sanitizedData = data.Trim(); + var parts = sanitizedData.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + if (parts.Length > 1 && charCount <= 2) { - var text = ""; - for (int i = 0; i < charCount; i++) + var text = string.Empty; + for (var i = 0; i < charCount; i++) { - text += parts[i].Substring(0, 1); + text += parts[i][0]; } return text; } - if (data.Length > 2) + if (sanitizedData.Length > 2) { - return data.Substring(0, 2); + return sanitizedData.Substring(0, 2); } - return data; + return sanitizedData; } private Color StringToColor(string str)