Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Hashids.net/Hashids.cs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,8 @@ private long[] GetNumbersFrom(string hash)
{
var result = NumbersFrom(hash);

Span<char> hashBuffer = hash.Length < MAX_STACKALLOC_SIZE ? stackalloc char[hash.Length] : new char[hash.Length];
int bufferSizeToAllocate = Math.Max(hash.Length, _minHashLength);
Span<char> hashBuffer = bufferSizeToAllocate < MAX_STACKALLOC_SIZE ? stackalloc char[bufferSizeToAllocate] : new char[bufferSizeToAllocate];
var hashLength = GenerateHashFrom(result, ref hashBuffer);
if (hashLength == -1)
return Array.Empty<long>();
Expand Down
9 changes: 9 additions & 0 deletions test/Hashids.net.test/IssueSpecificTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,14 @@ void Issue75_TooShortHashWithLargerHashLengthShouldNotThrowException()
var hashids = new Hashids("salt", 40);
Assert.Throws<NoResultException>(() => hashids.DecodeSingle("ab"));
}

[Fact]
void Issue85_hash_shorter_than_min_length_should_not_throw_exception()
{
Hashids hashids = new Hashids(salt: "Dqa2s3RJBYPHUzg&R5qkF3Z4HLaWp#A^kMc^DqKVmqag2tasQjhz-PSM23=4", minHashLength: 8);
int[] numbers = hashids.Decode("5111111"); // Length = 7

Assert.Empty(numbers);
}
}
}