Skip to content

Commit 35f5264

Browse files
committed
Just allowed for toString format paramter to be passed through if its a buffer instance #201
1 parent 4616989 commit 35f5264

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/bson/objectid.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,17 @@ ObjectID.prototype.generate = function(time) {
149149
/**
150150
* Converts the id into a 24 byte hex string for printing
151151
*
152+
* @param {String} format The Buffer toString format parameter.
152153
* @return {String} return the 24 byte hex string representation.
153154
* @ignore
154155
*/
155-
ObjectID.prototype.toString = function() {
156+
ObjectID.prototype.toString = function(format) {
157+
// Is the id a buffer then use the buffer toString method to return the format
158+
if(this.id instanceof Buffer) {
159+
return this.id.toString(format || 'hex');
160+
}
161+
162+
// if(this.buffer )
156163
return this.toHexString();
157164
};
158165

test/node/object_id_tests.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,5 @@ exports['should correctly create ObjectId from Buffer'] = function(test) {
5252
var c = b.equals(a); // => true
5353
test.equal(a, b.toString());
5454
test.equal(true, c);
55-
5655
test.done();
5756
}

0 commit comments

Comments
 (0)