1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-05 23:53:33 +00:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Andre Rosado
2a8663f1f0 PS-1174 Fixed Formatting 2022-12-28 17:12:10 +00:00
Andre Rosado
b35bb7a7a6 PS-1174 - Validating if vault item name and subtitle without diacritics has a match on search 2022-12-28 15:40:09 +00:00

View File

@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Bit.Core.Abstractions;
@@ -85,6 +87,10 @@ namespace Bit.Core.Services
{
matchedCiphers.Add(c);
}
else if (RemoveDiacritics(c.Name)?.ToLower().Contains(query) ?? false)
{
lowPriorityMatchedCiphers.Add(c);
}
else if (query.Length >= 8 && c.Id.StartsWith(query))
{
lowPriorityMatchedCiphers.Add(c);
@@ -93,6 +99,10 @@ namespace Bit.Core.Services
{
lowPriorityMatchedCiphers.Add(c);
}
else if (RemoveDiacritics(c.SubTitle)?.ToLower().Contains(query) ?? false)
{
lowPriorityMatchedCiphers.Add(c);
}
else if (c.Login?.Uri?.ToLower()?.Contains(query) ?? false)
{
lowPriorityMatchedCiphers.Add(c);
@@ -165,5 +175,27 @@ namespace Bit.Core.Services
matchedSends.AddRange(lowPriorityMatchSends);
return matchedSends;
}
private string RemoveDiacritics(string text)
{
if (string.IsNullOrWhiteSpace(text))
{
return null;
}
string formD = text.Normalize(NormalizationForm.FormD);
StringBuilder sb = new StringBuilder();
foreach (char ch in formD)
{
UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(ch);
if (uc != UnicodeCategory.NonSpacingMark)
{
sb.Append(ch);
}
}
return sb.ToString().Normalize(NormalizationForm.FormC);
}
}
}