Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2012-01-14 05:13:22 +0400
committerBen Noordhuis <info@bnoordhuis.nl>2012-01-14 05:13:24 +0400
commitf0c1376e07e6d5a4deb3d088bd3153d7f6af1298 (patch)
tree2591465edfda9760c8cff7d0c56947ccb2771bbc /lib
parent766f609838734f7ddf2ee9503e8205647ecb5dbf (diff)
net: make .write() throw on bad input
Passing a non-buffer or non-string argument to Socket.prototype.write triggered an assert: Assertion failed: (Buffer::HasInstance(args[0])), function Write, file ../src/stream_wrap.cc, line 289. Fixes #2532.
Diffstat (limited to 'lib')
-rw-r--r--lib/net.js4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/net.js b/lib/net.js
index 072896b4c4e..85479412b2d 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -424,8 +424,10 @@ Socket.prototype.write = function(data, arg1, arg2) {
}
// Change strings to buffers. SLOW
- if (typeof data == 'string') {
+ if (typeof data === 'string') {
data = new Buffer(data, encoding);
+ } else if (!Buffer.isBuffer(data)) {
+ throw new TypeError("First argument must be a buffer or a string.");
}
this.bytesWritten += data.length;