Skip to content

Commit 8c9800c

Browse files
amitzurtargos
authored andcommitted
crypto: include 'Buffer' in error output of Hash.update method
Fixes: #25487 PR-URL: #25533 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 85d5f67 commit 8c9800c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/internal/crypto/hash.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ Hash.prototype.update = function update(data, encoding) {
6262

6363
if (typeof data !== 'string' && !isArrayBufferView(data)) {
6464
throw new ERR_INVALID_ARG_TYPE('data',
65-
['string', 'TypedArray', 'DataView'], data);
65+
['string',
66+
'Buffer',
67+
'TypedArray',
68+
'DataView'],
69+
data);
6670
}
6771

6872
if (!this[kHandle].update(data, encoding || getDefaultEncoding()))

test/parallel/test-crypto-hash.js

+11
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ common.expectsError(
122122
message: 'boom'
123123
});
124124

125+
// Issue https://github.com/nodejs/node/issues/25487: error message for invalid
126+
// arg type to update method should include all possible types
127+
common.expectsError(
128+
() => crypto.createHash('sha256').update(),
129+
{
130+
code: 'ERR_INVALID_ARG_TYPE',
131+
type: TypeError,
132+
message: 'The "data" argument must be one of type string, Buffer, ' +
133+
'TypedArray, or DataView. Received type undefined'
134+
});
135+
125136
// Default UTF-8 encoding
126137
const hutf8 = crypto.createHash('sha512').update('УТФ-8 text').digest('hex');
127138
assert.strictEqual(

0 commit comments

Comments
 (0)