mirror of
https://github.com/bitwarden/mobile
synced 2026-02-17 18:09:05 +00:00
PS-1174 - Validating if vault item name and subtitle without diacritics has a match on search
This commit is contained in:
@@ -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;
|
||||
@@ -84,6 +86,9 @@ namespace Bit.Core.Services
|
||||
if (c.Name?.ToLower().Contains(query) ?? false)
|
||||
{
|
||||
matchedCiphers.Add(c);
|
||||
}else if(RemoveDiacritics(c.Name)?.ToLower().Contains(query) ?? false)
|
||||
{
|
||||
lowPriorityMatchedCiphers.Add(c);
|
||||
}
|
||||
else if (query.Length >= 8 && c.Id.StartsWith(query))
|
||||
{
|
||||
@@ -93,6 +98,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 +174,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user