From 4f32a59307b15ce5c3b9d543b16ed90470b1132e Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 23 Nov 2010 12:20:22 -0800 Subject: [PATCH] Fix buffer.slice(0, 0) --- lib/buffer.js | 2 +- test/simple/test-buffer.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/buffer.js b/lib/buffer.js index d2b87ecdb96..b777bf0725f 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -322,7 +322,7 @@ Buffer.prototype.copy = function copy (target, target_start, start, end) { // slice(start, end) Buffer.prototype.slice = function (start, end) { - if (!end) end = this.length; + if (end === undefined) end = this.length; if (end > this.length) throw new Error("oob"); if (start > end) throw new Error("oob"); diff --git a/test/simple/test-buffer.js b/test/simple/test-buffer.js index 26ebd4798a2..d98da04ed90 100644 --- a/test/simple/test-buffer.js +++ b/test/simple/test-buffer.js @@ -353,3 +353,7 @@ assert.equal(14, Buffer.byteLength("Il était tué")); assert.equal(14, Buffer.byteLength("Il était tué", "utf8")); assert.equal(12, Buffer.byteLength("Il était tué", "ascii")); assert.equal(12, Buffer.byteLength("Il était tué", "binary")); + + +// slice(0,0).length === 0 +assert.equal(0, Buffer('hello').slice(0, 0).length)