Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream,net: slightly more consistent typechecking #17644

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
stream: remove undefined check
`validChunk` allowed `undefined` as a chunk in object mode; however,
this was redundant, since:

- `validChunk()` is only used by `.write()`
- If the `validChunk()` check passes for `undefined`, `.write()`
  calls `writeOrBuffer()`
- If `writeOrBuffer()` does not receive a Buffer, it calls
  `decodeChunk()`
  - `decodeChunk()` ignores `undefined` because it checks
    `typeof chunk === 'string'`
  - After that call, `chunk.length` is accessed, which throws an
    error if `chunk` is undefined`.

This “fixes” a bug in the sense that `state.pendingcb` is no longer
incremented for write attempts that fail like this.
addaleax committed Dec 13, 2017
commit abd765892807499103800f6f23e44ef2a5a68c0b
4 changes: 1 addition & 3 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
@@ -249,9 +249,7 @@ function validChunk(stream, state, chunk, cb) {

if (chunk === null) {
er = new errors.TypeError('ERR_STREAM_NULL_VALUES');
} else if (typeof chunk !== 'string' &&
chunk !== undefined &&
!state.objectMode) {
} else if (typeof chunk !== 'string' && !state.objectMode) {
er = new errors.TypeError('ERR_INVALID_ARG_TYPE', 'chunk',
['string', 'Buffer']);
}