Skip to content

Commit

Permalink
Check blocked words against alphabet case-insensitively
Browse files Browse the repository at this point in the history
  • Loading branch information
aradalvand committed Aug 30, 2023
1 parent 5217f58 commit 606eba7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Sqids/SqidsEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,14 @@ public SqidsEncoder(SqidsOptions options)
StringComparer.OrdinalIgnoreCase // NOTE: Effectively removes items that differ only in casing — leaves one version of each word casing-wise which will then be compared against the generated IDs case-insensitively
);
options.BlockList.RemoveWhere(w =>
w.Length < 3 || // NOTE: Removes words that are less than 3 characters long
w.Any(c => !options.Alphabet.Contains(c)) // NOTE: Removes words that contain characters not found in the alphabet
// NOTE: Removes words that are less than 3 characters long
w.Length < 3 ||
// NOTE: Removes words that contain characters not found in the alphabet
#if NETSTANDARD2_0
w.Any(c => options.Alphabet.IndexOf(c.ToString(), StringComparison.OrdinalIgnoreCase) == -1) // NOTE: A `string.Contains` overload with `StringComparison` didn't exist prior to .NET Standard 2.1, so we have to resort to `IndexOf` — see https://stackoverflow.com/a/52791476
#else
w.Any(c => !options.Alphabet.Contains(c, StringComparison.OrdinalIgnoreCase))
#endif
);
_blockList = options.BlockList.ToArray(); // NOTE: Arrays are faster to iterate than HashSets, so we construct an array here.

Expand Down

0 comments on commit 606eba7

Please sign in to comment.