GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: disallow writing string chunk with 'buffer' encoding · nodejs/node@fce3df7

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/streams
    • writable.js
  • src
    • stream_base.cc
  • test/parallel
    • test-stream-base-typechecking.js
    • test-stream-writable-write-error.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/streams/writable.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/writable.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ function _write(stream, chunk, encoding, cb) {
466466
}
467467

468468
if (typeof chunk === 'string') {
469+
if (encoding === 'buffer') {
470+
throw new ERR_UNKNOWN_ENCODING(encoding);
471+
}
469472
if ((state[kState] & kDecodeStrings) !== 0) {
470473
chunk = Buffer.from(chunk, encoding);
471474
encoding = 'buffer';
Collapse file

‎src/stream_base.cc‎

Copy file name to clipboardExpand all lines: src/stream_base.cc
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,10 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
296296

297297
int StreamBase::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
298298
CHECK(args[0]->IsObject());
299+
CHECK(args[1]->IsUint8Array());
299300

300301
Environment* env = Environment::GetCurrent(args);
301302

302-
if (!args[1]->IsUint8Array()) {
303-
node::THROW_ERR_INVALID_ARG_TYPE(env, "Second argument must be a buffer");
304-
return 0;
305-
}
306-
307303
Local<Object> req_wrap_obj = args[0].As<Object>();
308304
uv_buf_t buf;
309305
buf.base = Buffer::Data(args[1]);
Collapse file

‎test/parallel/test-stream-base-typechecking.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-base-typechecking.js
-18Lines changed: 0 additions & 18 deletions
This file was deleted.
Collapse file

‎test/parallel/test-stream-writable-write-error.js‎

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 numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function test(autoDestroy) {
3131
{
3232
const w = new Writable({
3333
autoDestroy,
34-
_write() {}
34+
write() {}
3535
});
3636
w.end();
3737
expectError(w, ['asd'], 'ERR_STREAM_WRITE_AFTER_END');
@@ -40,34 +40,42 @@ function test(autoDestroy) {
4040
{
4141
const w = new Writable({
4242
autoDestroy,
43-
_write() {}
43+
write() {}
4444
});
4545
w.destroy();
4646
}
4747

4848
{
4949
const w = new Writable({
5050
autoDestroy,
51-
_write() {}
51+
write() {}
5252
});
5353
expectError(w, [null], 'ERR_STREAM_NULL_VALUES', true);
5454
}
5555

5656
{
5757
const w = new Writable({
5858
autoDestroy,
59-
_write() {}
59+
write() {}
6060
});
6161
expectError(w, [{}], 'ERR_INVALID_ARG_TYPE', true);
6262
}
6363

6464
{
6565
const w = new Writable({
66-
decodeStrings: false,
6766
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() {}
6977
});
70-
expectError(w, ['asd', 'noencoding'], 'ERR_UNKNOWN_ENCODING', true);
78+
expectError(w, ['asd', 'buffer'], 'ERR_UNKNOWN_ENCODING', true);
7179
}
7280
}
7381

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.