angular-md5 icon indicating copy to clipboard operation
angular-md5 copied to clipboard

Crash when generating hashes for single-digit numbers

Open blaues0cke opened this issue 10 years ago • 1 comments

This code will throw some js errors:

var currentId = 1;

FormIDProvider.getCurrentId = function (raw)
{
    if (raw)
    {
        return currentId;
    }

    return 'form-field-' + md5.createHash(currentId);
};

The console says:

RangeError: Invalid array length
   at convertToWordArray (/assets/js/angular/angular-md5.js:88:28)
    at Object.md5.createHash (/assets/js/angular/angular-md5.js:114:13)

As a workaround, this will help:

return 'form-field-' + md5.createHash('seed' + currentId);

blaues0cke avatar Jun 19 '15 08:06 blaues0cke

If you cast your int to String via currentId.toString(), the error won't be thrown.

karsasmus avatar Sep 25 '15 03:09 karsasmus