Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

null or empty string are decoded as empty arrays. #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions src/Hashids.net/Hashids.cs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,9 @@ private long GetNumberFrom(string hash)

private long[] GetNumbersFrom(string hash)
{
if (string.IsNullOrWhiteSpace(hash))
return Array.Empty<long>();

var result = NumbersFrom(hash);

int bufferSizeToAllocate = Math.Max(hash.Length, _minHashLength);
Expand All @@ -583,9 +586,6 @@ private long[] GetNumbersFrom(string hash)

private long[] NumbersFrom(string hash)
{
if (string.IsNullOrWhiteSpace(hash))
return Array.Empty<long>();

var guardedHash = hash.AsSpan();
var (count, ranges) = Split(guardedHash, _guards);

Expand Down
11 changes: 11 additions & 0 deletions test/Hashids.net.test/IssueSpecificTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,16 @@ void Issue85_hash_shorter_than_min_length_should_not_throw_exception()

Assert.Empty(numbers);
}

[Theory]
[InlineData(null)]
[InlineData("")]
void Issue93_decoding_null_or_empty_string_should_return_empty_array(string input)
{
var hashids = new Hashids("salt");
int[] numbers = hashids.Decode(input);

Assert.Empty(numbers);
}
}
}