Commit 9fd3807a by Jose Carlos López

Fix criteria exception to a 12chars string conversion

parent deb463f9
Showing with 13 additions and 2 deletions
var ObjectID = require('bson').ObjectID; var ObjectID = require('bson').ObjectID;
var objectIDRegex = new RegExp(/^[0-9a-fA-F]{24}$/);
module.exports = { module.exports = {
isObjectID: function (value) { return ObjectID.isValid(value); }, isObjectID: function (value) {
// NOTE We need to check that its a 24hex string because
// a 12 chars string is a valid objectID but we dont want it replaced
// by an objectid type
return ObjectID.isValid(value) && objectIDRegex.test(value);
},
toObjectID: function (value) { return ObjectID(value); } toObjectID: function (value) { return ObjectID(value); }
}; };
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
"test": "node_modules/mocha/bin/mocha test" "test": "node_modules/mocha/bin/mocha test"
}, },
"dependencies": { "dependencies": {
"bson": "^0.4.23" "bson": "^1.0.4"
}, },
"publishConfig": { "publishConfig": {
"registry": "http://192.168.1.199:4873/" "registry": "http://192.168.1.199:4873/"
......
...@@ -172,6 +172,11 @@ describe("query-to-mongo(query) =>", function () { ...@@ -172,6 +172,11 @@ describe("query-to-mongo(query) =>", function () {
assert.ok(results) assert.ok(results)
assert.deepEqual(results, {d: ObjectID('574553013b58d8582cdb1d5f')}) assert.deepEqual(results, {d: ObjectID('574553013b58d8582cdb1d5f')})
}) })
it("should not create mongo objectID criteria fom a 12 chars string", function () {
var results = q2m("d=llosaderanes")
assert.ok(results)
assert.deepEqual(results, {d: 'llosaderanes'})
})
}) })
describe(".options", function () { describe(".options", function () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment