PatrickJS / angular-md5

md5 for Angular.js and Gravatar filter
MIT License
132 stars 55 forks source link

Crash when generating hashes for single-digit numbers #7

Open blaues0cke opened 9 years ago

blaues0cke commented 9 years ago

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);
karsasmus commented 9 years ago

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