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
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
null or empty string are decoded as empty arrays.
Eduard Llull Pou committed Oct 25, 2023

Verified

This commit was signed with the committer’s verified signature.
commit da02a36d820c02d1e126efc2ea759d9a6ce102da
6 changes: 3 additions & 3 deletions src/Hashids.net/Hashids.cs
Original file line number Diff line number Diff line change
@@ -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);
@@ -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);

11 changes: 11 additions & 0 deletions test/Hashids.net.test/IssueSpecificTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}