diff --git a/src/Sqids/SqidsEncoder.cs b/src/Sqids/SqidsEncoder.cs index 8cab01f..5fe3f19 100644 --- a/src/Sqids/SqidsEncoder.cs +++ b/src/Sqids/SqidsEncoder.cs @@ -81,6 +81,12 @@ public SqidsEncoder(SqidsOptions options) $"The alphabet must contain at least {MinAlphabetLength} characters." ); + if (Encoding.UTF8.GetByteCount(options.Alphabet) != options.Alphabet.Length) + throw new ArgumentOutOfRangeException( + nameof(options.MinLength), + $"The alphabet must not contain multi-byte characters." + ); + if (options.MinLength < 0 || options.MinLength > MaxMinLength) throw new ArgumentOutOfRangeException( nameof(options.MinLength), diff --git a/test/Sqids.Tests/AlphabetTests.cs b/test/Sqids.Tests/AlphabetTests.cs index c611e5e..31ab9b3 100644 --- a/test/Sqids.Tests/AlphabetTests.cs +++ b/test/Sqids.Tests/AlphabetTests.cs @@ -39,6 +39,7 @@ int[] numbers [TestCase("aabcdefg")] // NOTE: Repeated characters [TestCase("ab")] // NOTE: Too short + [TestCase("ë1092")] // NOTE: Contains a multi-byte character public void Instantiate_WithInvalidAlphabet_Throws(string invalidAlphabet) { #if NET7_0_OR_GREATER