Fix buffer.slice(0, 0)

This commit is contained in:
Ryan Dahl 2010-11-23 12:20:22 -08:00
parent f123a1ab40
commit 4f32a59307
2 changed files with 5 additions and 1 deletions

View File

@ -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");

View File

@ -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)