Closed philbayer closed 7 years ago
Fixed.
When encoding negative numbers, the result should be ""
(empty string), same behaviour as the javascript implementation.
https://github.com/ivanakimov/hashids.js/blob/master/lib/hashids.js#L111-L115
Just to make it clear, the fix has not been released. It has been fixed in HEAD.
Problem: If the list of longs passed to the method
public String encode(long... numbers)
contains a negative value, it may result in ajava.lang.ArrayIndexOutOfBoundsException
being thrown. Here is the offending code snippet (see added inline comments.Possible Solutions: 1) In the method
public String encode(long... numbers)
replace the following lineif (number > 9007199254740992L) {
with
if (number > 9007199254740992L || number < 0) {
2) In the method
private String _encode(long... numbers)
use the absolute value of the long values in numbers when computing the hash: