Skip to content

Commit 606eba7

Browse files
committed
Check blocked words against alphabet case-insensitively
Reflects sqids/sqids-spec#7
1 parent 5217f58 commit 606eba7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Sqids/SqidsEncoder.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,14 @@ public SqidsEncoder(SqidsOptions options)
110110
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
111111
);
112112
options.BlockList.RemoveWhere(w =>
113-
w.Length < 3 || // NOTE: Removes words that are less than 3 characters long
114-
w.Any(c => !options.Alphabet.Contains(c)) // NOTE: Removes words that contain characters not found in the alphabet
113+
// NOTE: Removes words that are less than 3 characters long
114+
w.Length < 3 ||
115+
// NOTE: Removes words that contain characters not found in the alphabet
116+
#if NETSTANDARD2_0
117+
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
118+
#else
119+
w.Any(c => !options.Alphabet.Contains(c, StringComparison.OrdinalIgnoreCase))
120+
#endif
115121
);
116122
_blockList = options.BlockList.ToArray(); // NOTE: Arrays are faster to iterate than HashSets, so we construct an array here.
117123

0 commit comments

Comments
 (0)