0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-stream-wrap-encoding.js
Fedor Indutny de2fd63612 stream_wrap: error if stream has StringDecoder
If `.setEncoding` was called on input stream - all emitted `data` will
be `String`s instances, not `Buffer`s. This is unacceptable for
`StreamWrap`, and should not lead to the crash.

Fix: https://github.com/nodejs/node/issues/3970
PR-URL: https://github.com/nodejs/node/pull/4031
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2015-12-06 21:55:25 -05:00

24 lines
446 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const StreamWrap = require('_stream_wrap');
const Duplex = require('stream').Duplex;
const stream = new Duplex({
read: function() {
},
write: function() {
}
});
stream.setEncoding('ascii');
const wrap = new StreamWrap(stream);
wrap.on('error', common.mustCall(function(err) {
assert(/StringDecoder/.test(err.message));
}));
stream.push('ohai');