File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -567,7 +567,8 @@ private long[] GetNumbersFrom(string hash)
567567 {
568568 var result = NumbersFrom ( hash ) ;
569569
570- Span < char > hashBuffer = hash . Length < MAX_STACKALLOC_SIZE ? stackalloc char [ hash . Length ] : new char [ hash . Length ] ;
570+ int bufferSizeToAllocate = Math . Max ( hash . Length , _minHashLength ) ;
571+ Span < char > hashBuffer = bufferSizeToAllocate < MAX_STACKALLOC_SIZE ? stackalloc char [ bufferSizeToAllocate ] : new char [ bufferSizeToAllocate ] ;
571572 var hashLength = GenerateHashFrom ( result , ref hashBuffer ) ;
572573 if ( hashLength == - 1 )
573574 return Array . Empty < long > ( ) ;
Original file line number Diff line number Diff line change @@ -86,5 +86,14 @@ void Issue75_TooShortHashWithLargerHashLengthShouldNotThrowException()
8686 var hashids = new Hashids ( "salt" , 40 ) ;
8787 Assert . Throws < NoResultException > ( ( ) => hashids . DecodeSingle ( "ab" ) ) ;
8888 }
89+
90+ [ Fact ]
91+ void Issue85_hash_shorter_than_min_length_should_not_throw_exception ( )
92+ {
93+ Hashids hashids = new Hashids ( salt : "Dqa2s3RJBYPHUzg&R5qkF3Z4HLaWp#A^kMc^DqKVmqag2tasQjhz-PSM23=4" , minHashLength : 8 ) ;
94+ int [ ] numbers = hashids . Decode ( "5111111" ) ; // Length = 7
95+
96+ Assert . Empty ( numbers ) ;
97+ }
8998 }
9099}
You can’t perform that action at this time.
0 commit comments