diff --git a/lib/internal/crypto/hash.js b/lib/internal/crypto/hash.js index 7c697eb4772a19..3284604495026e 100644 --- a/lib/internal/crypto/hash.js +++ b/lib/internal/crypto/hash.js @@ -62,7 +62,11 @@ Hash.prototype.update = function update(data, encoding) { if (typeof data !== 'string' && !isArrayBufferView(data)) { throw new ERR_INVALID_ARG_TYPE('data', - ['string', 'TypedArray', 'DataView'], data); + ['string', + 'Buffer', + 'TypedArray', + 'DataView'], + data); } if (!this[kHandle].update(data, encoding || getDefaultEncoding())) diff --git a/test/parallel/test-crypto-hash.js b/test/parallel/test-crypto-hash.js index 5cc622b48c76c4..60904cf08fec3d 100644 --- a/test/parallel/test-crypto-hash.js +++ b/test/parallel/test-crypto-hash.js @@ -122,6 +122,17 @@ common.expectsError( message: 'boom' }); +// Issue https://github.com/nodejs/node/issues/25487: error message for invalid +// arg type to update method should include all possible types +common.expectsError( + () => crypto.createHash('sha256').update(), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "data" argument must be one of type string, Buffer, ' + + 'TypedArray, or DataView. Received type undefined' + }); + // Default UTF-8 encoding const hutf8 = crypto.createHash('sha512').update('УТФ-8 text').digest('hex'); assert.strictEqual(