Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
#204 remove Buffer.from as it's partially broken in early 4.x.x. seri…
Browse files Browse the repository at this point in the history
…es of node releases. updated version to V1.0.4
  • Loading branch information
christkv committed Jan 11, 2017
1 parent a098ee8 commit 18a6038
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.0.4 2016-01-11
----------------
- #204 remove Buffer.from as it's partially broken in early 4.x.x. series of node releases.

1.0.3 2016-01-03
----------------
- Fixed toString for ObjectId so it will work with inspect.
Expand Down
4 changes: 2 additions & 2 deletions lib/bson/objectid.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var ObjectID = function ObjectID(id) {
if(!valid && id != null){
throw new Error("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters");
} else if(valid && typeof id == 'string' && id.length == 24 && hasBufferType) {
return new ObjectID(Buffer.from(id, 'hex'));
return new ObjectID(new Buffer(id, 'hex'));
} else if(valid && typeof id == 'string' && id.length == 24) {
return ObjectID.createFromHexString(id);
} else if(id != null && id.length === 12) {
Expand Down Expand Up @@ -290,7 +290,7 @@ ObjectID.createFromHexString = function createFromHexString (string) {
}

// Use Buffer.from method if available
if(hasBufferType) return new ObjectID(Buffer.from(string, 'hex'));
if(hasBufferType) return new ObjectID(new Buffer(string, 'hex'));

// Calculate lengths
var array = new _Buffer(12);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bson",
"parser"
],
"version": "1.0.3",
"version": "1.0.4",
"author": "Christian Amor Kvalheim <[email protected]>",
"contributors": [],
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions test/node/object_id_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ exports['should correctly create ObjectId from uppercase hexstring'] = function(
exports['should correctly create ObjectId from Buffer'] = function(test) {
if(!Buffer.from) return test.done();
var a = 'AAAAAAAAAAAAAAAAAAAAAAAA';
var b = new ObjectId(Buffer.from(a, 'hex'));
var b = new ObjectId(new Buffer(a, 'hex'));
var c = b.equals(a); // => false
test.equal(true, c);

var a = 'aaaaaaaaaaaaaaaaaaaaaaaa';
var b = new ObjectId(Buffer.from(a, 'hex'));
var b = new ObjectId(new Buffer(a, 'hex'));
var c = b.equals(a); // => true
test.equal(a, b.toString());
test.equal(true, c);
Expand Down

0 comments on commit 18a6038

Please sign in to comment.