crypto: fix utf8/utf-8 encoding check
Normalize the encoding in getEncoding() before using it. Fixes a "AssertionError: Cannot change encoding" exception when the caller mixes "utf8" and "utf-8". Fixes #5655.
This commit is contained in:
parent
f1b878cafa
commit
82b3524bce
@ -236,6 +236,7 @@ Hmac.prototype._transform = Hash.prototype._transform;
|
|||||||
|
|
||||||
|
|
||||||
function getDecoder(decoder, encoding) {
|
function getDecoder(decoder, encoding) {
|
||||||
|
if (encoding === 'utf-8') encoding = 'utf8'; // Normalize encoding.
|
||||||
decoder = decoder || new StringDecoder(encoding);
|
decoder = decoder || new StringDecoder(encoding);
|
||||||
assert(decoder.encoding === encoding, 'Cannot change encoding');
|
assert(decoder.encoding === encoding, 'Cannot change encoding');
|
||||||
return decoder;
|
return decoder;
|
||||||
|
@ -900,3 +900,18 @@ assert.throws(function() {
|
|||||||
c.update('update');
|
c.update('update');
|
||||||
c.final();
|
c.final();
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
// #5655 regression tests, 'utf-8' and 'utf8' are identical.
|
||||||
|
(function() {
|
||||||
|
var c = crypto.createCipher('aes192', '0123456789abcdef');
|
||||||
|
c.update('update', ''); // Defaults to "utf8".
|
||||||
|
c.final('utf-8'); // Should not throw.
|
||||||
|
|
||||||
|
c = crypto.createCipher('aes192', '0123456789abcdef');
|
||||||
|
c.update('update', 'utf8');
|
||||||
|
c.final('utf-8'); // Should not throw.
|
||||||
|
|
||||||
|
c = crypto.createCipher('aes192', '0123456789abcdef');
|
||||||
|
c.update('update', 'utf-8');
|
||||||
|
c.final('utf8'); // Should not throw.
|
||||||
|
})();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user