Skip to content

Commit 9e4b56b

Browse files
committed
#204 remove Buffer.from as it's partially broken in early 4.x.x. series of node releases
1 parent ca1447a commit 9e4b56b

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/bson/objectid.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ var ObjectID = function ObjectID(id) {
4949
if(!valid && id != null){
5050
throw new Error("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters");
5151
} else if(valid && typeof id == 'string' && id.length == 24 && hasBufferType) {
52-
return new ObjectID(Buffer.from(id, 'hex'));
52+
return new ObjectID(new Buffer(id, 'hex'));
5353
} else if(valid && typeof id == 'string' && id.length == 24) {
5454
return ObjectID.createFromHexString(id);
5555
} else if(id != null && id.length === 12) {
@@ -290,7 +290,7 @@ ObjectID.createFromHexString = function createFromHexString (string) {
290290
}
291291

292292
// Use Buffer.from method if available
293-
if(hasBufferType) return new ObjectID(Buffer.from(string, 'hex'));
293+
if(hasBufferType) return new ObjectID(new Buffer(string, 'hex'));
294294

295295
// Calculate lengths
296296
var array = new _Buffer(12);

test/node/object_id_tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ exports['should correctly create ObjectId from uppercase hexstring'] = function(
4444
exports['should correctly create ObjectId from Buffer'] = function(test) {
4545
if(!Buffer.from) return test.done();
4646
var a = 'AAAAAAAAAAAAAAAAAAAAAAAA';
47-
var b = new ObjectId(Buffer.from(a, 'hex'));
47+
var b = new ObjectId(new Buffer(a, 'hex'));
4848
var c = b.equals(a); // => false
4949
test.equal(true, c);
5050

5151
var a = 'aaaaaaaaaaaaaaaaaaaaaaaa';
52-
var b = new ObjectId(Buffer.from(a, 'hex'));
52+
var b = new ObjectId(new Buffer(a, 'hex'));
5353
var c = b.equals(a); // => true
5454
test.equal(a, b.toString());
5555
test.equal(true, c);

0 commit comments

Comments
 (0)