GeezerVison is showing github.com — stream: disallow writing string chunk with 'buffer' encoding · nodejs/node@fce3df7
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/streams/writable.js +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -466,6 +466,9 @@ function _write(stream, chunk, encoding, cb) { | 466 | 466 | } | 467 | 467 |
| 468 | 468 | if (typeof chunk === 'string') { | | 469 | + if (encoding === 'buffer') { | | 470 | + throw new ERR_UNKNOWN_ENCODING(encoding); | | 471 | + } | 469 | 472 | if ((state[kState] & kDecodeStrings) !== 0) { | 470 | 473 | chunk = Buffer.from(chunk, encoding); | 471 | 474 | encoding = 'buffer'; | |
Collapse file Copy file name to clipboardExpand all lines: src/stream_base.cc +1-5Lines changed: 1 addition & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -296,14 +296,10 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) { | 296 | 296 |
| 297 | 297 | int StreamBase::WriteBuffer(const FunctionCallbackInfo<Value>& args) { | 298 | 298 | CHECK(args[0]->IsObject()); | | 299 | + CHECK(args[1]->IsUint8Array()); | 299 | 300 |
| 300 | 301 | Environment* env = Environment::GetCurrent(args); | 301 | 302 |
| 302 | | - if (!args[1]->IsUint8Array()) { | 303 | | - node::THROW_ERR_INVALID_ARG_TYPE(env, "Second argument must be a buffer"); | 304 | | - return 0; | 305 | | - } | 306 | | - | 307 | 303 | Local<Object> req_wrap_obj = args[0].As<Object>(); | 308 | 304 | uv_buf_t buf; | 309 | 305 | buf.base = Buffer::Data(args[1]); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-stream-base-typechecking.js -18Lines changed: 0 additions & 18 deletions Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-stream-writable-write-error.js +15-7Lines changed: 15 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -31,7 +31,7 @@ function test(autoDestroy) { | 31 | 31 | { | 32 | 32 | const w = new Writable({ | 33 | 33 | autoDestroy, | 34 | | - _write() {} | | 34 | + write() {} | 35 | 35 | }); | 36 | 36 | w.end(); | 37 | 37 | expectError(w, ['asd'], 'ERR_STREAM_WRITE_AFTER_END'); | @@ -40,34 +40,42 @@ function test(autoDestroy) { | 40 | 40 | { | 41 | 41 | const w = new Writable({ | 42 | 42 | autoDestroy, | 43 | | - _write() {} | | 43 | + write() {} | 44 | 44 | }); | 45 | 45 | w.destroy(); | 46 | 46 | } | 47 | 47 |
| 48 | 48 | { | 49 | 49 | const w = new Writable({ | 50 | 50 | autoDestroy, | 51 | | - _write() {} | | 51 | + write() {} | 52 | 52 | }); | 53 | 53 | expectError(w, [null], 'ERR_STREAM_NULL_VALUES', true); | 54 | 54 | } | 55 | 55 |
| 56 | 56 | { | 57 | 57 | const w = new Writable({ | 58 | 58 | autoDestroy, | 59 | | - _write() {} | | 59 | + write() {} | 60 | 60 | }); | 61 | 61 | expectError(w, [{}], 'ERR_INVALID_ARG_TYPE', true); | 62 | 62 | } | 63 | 63 |
| 64 | 64 | { | 65 | 65 | const w = new Writable({ | 66 | | - decodeStrings: false, | 67 | 66 | autoDestroy, | 68 | | - _write() {} | | 67 | + write() {} | | 68 | + }); | | 69 | + expectError(w, ['asd', 'buffer'], 'ERR_UNKNOWN_ENCODING', true); | | 70 | + } | | 71 | + | | 72 | + { | | 73 | + const w = new Writable({ | | 74 | + autoDestroy, | | 75 | + decodeStrings: false, | | 76 | + write() {} | 69 | 77 | }); | 70 | | - expectError(w, ['asd', 'noencoding'], 'ERR_UNKNOWN_ENCODING', true); | | 78 | + expectError(w, ['asd', 'buffer'], 'ERR_UNKNOWN_ENCODING', true); | 71 | 79 | } | 72 | 80 | } | 73 | 81 |
| |
|