From 0474ce67908c9afddab69d3f0eb53564b10e2ad1 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 15 Feb 2011 12:07:43 -0800 Subject: [PATCH] Revert "buffer.toString() shouldn't include null values" This reverts commit 909a5b39d20f3cb72ed8c102b181ee46b886a54e. Will fix inside V8's String::New instead. --- src/node_buffer.cc | 10 +++------- test/simple/test-buffer.js | 12 ------------ 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index b7c5d859ad..8b48f2a2e6 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -232,8 +232,7 @@ Handle Buffer::AsciiSlice(const Arguments &args) { SLICE_ARGS(args[0], args[1]) char* data = parent->data_ + start; - size_t len = strnlen(data, end - start); - Local string = String::New(data, len); + Local string = String::New(data, end - start); return scope.Close(string); } @@ -243,13 +242,11 @@ Handle Buffer::Utf8Slice(const Arguments &args) { HandleScope scope; Buffer *parent = ObjectWrap::Unwrap(args.This()); SLICE_ARGS(args[0], args[1]) - char* data = parent->data_ + start; - size_t len = strnlen(data, end - start); - Local string = String::New(data, len); + char *data = parent->data_ + start; + Local string = String::New(data, end - start); return scope.Close(string); } - Handle Buffer::Ucs2Slice(const Arguments &args) { HandleScope scope; Buffer *parent = ObjectWrap::Unwrap(args.This()); @@ -259,7 +256,6 @@ Handle Buffer::Ucs2Slice(const Arguments &args) { return scope.Close(string); } - static const char *base64_table = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; diff --git a/test/simple/test-buffer.js b/test/simple/test-buffer.js index 5db92283f4..0aad8149f7 100644 --- a/test/simple/test-buffer.js +++ b/test/simple/test-buffer.js @@ -410,15 +410,3 @@ assert.equal(12, Buffer.byteLength('Il était tué', 'binary')); // slice(0,0).length === 0 assert.equal(0, Buffer('hello').slice(0, 0).length); - - -// toString('utf8') should not include null values -var b = new Buffer(20); -for (var i = 0; i < b.length; i++) { - b[i] = 0; -} -b.write('hello'); -assert.equal('hello', b.toString('utf8')); -assert.equal('hello', b.toString('ascii')); - -