aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy J Fontaine <tjfontaine@gmail.com>2013-05-23 16:23:07 -0700
committerTimothy J Fontaine <tjfontaine@gmail.com>2013-05-23 16:32:04 -0700
commit007e63bb13b5d3af54081972ab88217571828906 (patch)
treeac48de8f2d94c849e88e288fb6145558f546b748
parenta2f93cf77a8121db713bb003e26031bcca446f1f (diff)
downloadandroid-node-v8-007e63bb13b5d3af54081972ab88217571828906.tar.gz
android-node-v8-007e63bb13b5d3af54081972ab88217571828906.tar.bz2
android-node-v8-007e63bb13b5d3af54081972ab88217571828906.zip
buffer: special case empty string writes
Prior to 119354f we specifically handled passing a zero length string to write on a buffer, restore that functionality.
-rw-r--r--src/node_buffer.cc10
-rw-r--r--test/simple/test-buffer.js7
2 files changed, 16 insertions, 1 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc
index 2dfddc7644..8153c8319a 100644
--- a/src/node_buffer.cc
+++ b/src/node_buffer.cc
@@ -345,7 +345,15 @@ Handle<Value> Buffer::StringWrite(const Arguments& args) {
Local<String> str = args[0].As<String>();
- if (encoding == HEX && str->Length() % 2 != 0)
+ int length = str->Length();
+
+ if (length == 0) {
+ constructor_template->GetFunction()->Set(chars_written_sym,
+ Integer::New(0));
+ return scope.Close(Integer::New(0));
+ }
+
+ if (encoding == HEX && length % 2 != 0)
return ThrowTypeError("Invalid hex string");
size_t offset = args[1]->Int32Value();
diff --git a/test/simple/test-buffer.js b/test/simple/test-buffer.js
index 0d071127c9..3026824f0a 100644
--- a/test/simple/test-buffer.js
+++ b/test/simple/test-buffer.js
@@ -998,3 +998,10 @@ assert.equal(Buffer.byteLength('aaaa==', 'base64'), 3);
assert.throws(function() {
Buffer('', 'buffer');
}, TypeError);
+
+assert.doesNotThrow(function () {
+ var slow = new SlowBuffer(1);
+ assert(slow.write('', Buffer.poolSize * 10) === 0);
+ var fast = new Buffer(1);
+ assert(fast.write('', Buffer.poolSize * 10) === 0);
+});