Skip to content

Commit 0474ce6

Browse files
committed
Revert "buffer.toString() shouldn't include null values"
This reverts commit 909a5b3. Will fix inside V8's String::New instead.
1 parent 909a5b3 commit 0474ce6

2 files changed

Lines changed: 3 additions & 19 deletions

File tree

src/node_buffer.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ Handle<Value> Buffer::AsciiSlice(const Arguments &args) {
232232
SLICE_ARGS(args[0], args[1])
233233

234234
char* data = parent->data_ + start;
235-
size_t len = strnlen(data, end - start);
236-
Local<String> string = String::New(data, len);
235+
Local<String> string = String::New(data, end - start);
237236

238237
return scope.Close(string);
239238
}
@@ -243,13 +242,11 @@ Handle<Value> Buffer::Utf8Slice(const Arguments &args) {
243242
HandleScope scope;
244243
Buffer *parent = ObjectWrap::Unwrap<Buffer>(args.This());
245244
SLICE_ARGS(args[0], args[1])
246-
char* data = parent->data_ + start;
247-
size_t len = strnlen(data, end - start);
248-
Local<String> string = String::New(data, len);
245+
char *data = parent->data_ + start;
246+
Local<String> string = String::New(data, end - start);
249247
return scope.Close(string);
250248
}
251249

252-
253250
Handle<Value> Buffer::Ucs2Slice(const Arguments &args) {
254251
HandleScope scope;
255252
Buffer *parent = ObjectWrap::Unwrap<Buffer>(args.This());
@@ -259,7 +256,6 @@ Handle<Value> Buffer::Ucs2Slice(const Arguments &args) {
259256
return scope.Close(string);
260257
}
261258

262-
263259
static const char *base64_table = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
264260
"abcdefghijklmnopqrstuvwxyz"
265261
"0123456789+/";

test/simple/test-buffer.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -410,15 +410,3 @@ assert.equal(12, Buffer.byteLength('Il était tué', 'binary'));
410410

411411
// slice(0,0).length === 0
412412
assert.equal(0, Buffer('hello').slice(0, 0).length);
413-
414-
415-
// toString('utf8') should not include null values
416-
var b = new Buffer(20);
417-
for (var i = 0; i < b.length; i++) {
418-
b[i] = 0;
419-
}
420-
b.write('hello');
421-
assert.equal('hello', b.toString('utf8'));
422-
assert.equal('hello', b.toString('ascii'));
423-
424-

0 commit comments

Comments
 (0)