Skip to content

Commit eab4668

Browse files
committed
#201 fix for inspect passing in non string parameter to toString
1 parent 9569a93 commit eab4668

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/bson/objectid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ ObjectID.prototype.generate = function(time) {
171171
ObjectID.prototype.toString = function(format) {
172172
// Is the id a buffer then use the buffer toString method to return the format
173173
if(this.id && this.id.copy) {
174-
return this.id.toString(format || 'hex');
174+
return this.id.toString(typeof format === 'string' ? format : 'hex');
175175
}
176176

177177
// if(this.buffer )

test/node/object_id_tests.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var BSON = require('../..');
2+
var util = require('util');
23
var ObjectId = BSON.ObjectID;
34

45
/**
@@ -54,3 +55,23 @@ exports['should correctly create ObjectId from Buffer'] = function(test) {
5455
test.equal(true, c);
5556
test.done();
5657
}
58+
59+
/**
60+
* @ignore
61+
*/
62+
exports['should correctly allow for node.js inspect to work with ObjectId'] = function(test) {
63+
var a = 'AAAAAAAAAAAAAAAAAAAAAAAA';
64+
var b = new ObjectId(a);
65+
util.inspect(b);
66+
67+
// var c = b.equals(a); // => false
68+
// test.equal(true, c);
69+
//
70+
// var a = 'aaaaaaaaaaaaaaaaaaaaaaaa';
71+
// var b = new ObjectId(a);
72+
// var c = b.equals(a); // => true
73+
// test.equal(true, c);
74+
// test.equal(a, b.toString());
75+
76+
test.done();
77+
}

0 commit comments

Comments
 (0)