Comparing version
@@ -23,2 +23,5 @@ var QueryCommand = require('./commands/query_command').QueryCommand, | ||
// Ensure we have a valid db name | ||
validateDatabaseName(databaseName); | ||
// Contains all the connections for the db | ||
@@ -73,2 +76,12 @@ try { | ||
validateDatabaseName = function(databaseName) { | ||
if(typeof databaseName !== 'string') throw new Error("database name must be a string"); | ||
if(databaseName.length === 0) throw new Error("database name cannot be the empty string"); | ||
var invalidChars = [" ", ".", "$", "/", "\\"]; | ||
for(var i = 0; i < invalidChars.length; i++) { | ||
if(databaseName.indexOf(invalidChars[i]) != -1) throw new Error("database names cannot contain the character '" + invalidChars[i] + "'"); | ||
} | ||
} | ||
inherits(Db, EventEmitter); | ||
@@ -75,0 +88,0 @@ |
{ "name" : "mongodb" | ||
, "description" : "A node.js driver for MongoDB" | ||
, "keywords" : ["mongodb", "mongo", "driver", "db"] | ||
, "version" : "0.9.6-12" | ||
, "version" : "0.9.6-13" | ||
, "author" : "Christian Amor Kvalheim <christkv@gmail.com>" | ||
@@ -6,0 +6,0 @@ , "contributors" : [ "Aaron Heckmann", |
@@ -46,39 +46,89 @@ var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure(); | ||
// Test the auto connect functionality of the db | ||
shouldCorrectlyPerformAutomaticConnect : function(test) { | ||
var automatic_connect_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true}), {native_parser: (process.env['TEST_NATIVE'] != null)}); | ||
automatic_connect_client.bson_deserializer = client.bson_deserializer; | ||
automatic_connect_client.bson_serializer = client.bson_serializer; | ||
automatic_connect_client.pkFactory = client.pkFactory; | ||
automatic_connect_client.open(function(err, automatic_connect_client) { | ||
// Listener for closing event | ||
var closeListener = function(has_error) { | ||
shouldCorrectlyHandleIllegalDbNames : function(test) { | ||
// Assert rename | ||
try { | ||
new Db(5); | ||
} catch(err) { | ||
test.ok(err instanceof Error); | ||
test.equal("database name must be a string", err.message); | ||
} | ||
// Remove the listener for the close to avoid loop | ||
automatic_connect_client.removeListener("close", closeListener); | ||
// Let's insert a document | ||
automatic_connect_client.collection('test_object_id_generation.data2', function(err, collection) { | ||
try { | ||
new Db(""); | ||
} catch(err) { | ||
test.ok(err instanceof Error); | ||
test.equal("database name cannot be the empty string", err.message); | ||
} | ||
try { | ||
new Db("te$t", function(err, collection) {}); | ||
} catch(err) { | ||
test.equal("database names cannot contain the character '$'", err.message); | ||
} | ||
// Insert another test document and collect using ObjectId | ||
collection.insert({"name":"Patty", "age":34}, {safe:true}, function(err, ids) { | ||
test.equal(1, ids.length); | ||
test.ok(ids[0]._id.toHexString().length == 24); | ||
collection.findOne({"name":"Patty"}, function(err, document) { | ||
test.equal(ids[0]._id.toHexString(), document._id.toHexString()); | ||
// Let's close the db | ||
automatic_connect_client.close(); | ||
test.done(); | ||
}); | ||
}); | ||
}); | ||
}; | ||
// Add listener to close event | ||
automatic_connect_client.on("close", closeListener); | ||
automatic_connect_client.close(); | ||
}); | ||
try { | ||
new Db(".test", function(err, collection) {}); | ||
} catch(err) { | ||
test.equal("database names cannot contain the character '.'", err.message); | ||
} | ||
try { | ||
new Db("\\test", function(err, collection) {}); | ||
} catch(err) { | ||
test.equal("database names cannot contain the character '\\'", err.message); | ||
} | ||
try { | ||
new Db("\\test", function(err, collection) {}); | ||
} catch(err) { | ||
test.equal("database names cannot contain the character '\\'", err.message); | ||
} | ||
try { | ||
new Db("test test", function(err, collection) {}); | ||
} catch(err) { | ||
test.equal("database names cannot contain the character ' '", err.message); | ||
} | ||
test.done(); | ||
}, | ||
// // Test the auto connect functionality of the db | ||
// shouldCorrectlyPerformAutomaticConnect : function(test) { | ||
// var automatic_connect_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true}), {native_parser: (process.env['TEST_NATIVE'] != null)}); | ||
// automatic_connect_client.bson_deserializer = client.bson_deserializer; | ||
// automatic_connect_client.bson_serializer = client.bson_serializer; | ||
// automatic_connect_client.pkFactory = client.pkFactory; | ||
// | ||
// automatic_connect_client.open(function(err, automatic_connect_client) { | ||
// | ||
// // Listener for closing event | ||
// var closeListener = function(has_error) { | ||
// | ||
// // Remove the listener for the close to avoid loop | ||
// automatic_connect_client.removeListener("close", closeListener); | ||
// // Let's insert a document | ||
// automatic_connect_client.collection('test_object_id_generation.data2', function(err, collection) { | ||
// | ||
// // Insert another test document and collect using ObjectId | ||
// collection.insert({"name":"Patty", "age":34}, {safe:true}, function(err, ids) { | ||
// test.equal(1, ids.length); | ||
// test.ok(ids[0]._id.toHexString().length == 24); | ||
// | ||
// collection.findOne({"name":"Patty"}, function(err, document) { | ||
// test.equal(ids[0]._id.toHexString(), document._id.toHexString()); | ||
// // Let's close the db | ||
// automatic_connect_client.close(); | ||
// test.done(); | ||
// }); | ||
// }); | ||
// }); | ||
// }; | ||
// | ||
// // Add listener to close event | ||
// automatic_connect_client.on("close", closeListener); | ||
// automatic_connect_client.close(); | ||
// }); | ||
// }, | ||
// | ||
// // Test that error conditions are handled correctly | ||
@@ -198,45 +248,57 @@ // shouldCorrectlyHandleConnectionErrors : function(test) { | ||
// // Assert rename | ||
// collection1.rename(5, function(err, collection) { | ||
// try { | ||
// collection1.rename(5, function(err, collection) {}); | ||
// } catch(err) { | ||
// test.ok(err instanceof Error); | ||
// test.equal("collection name must be a String", err.message); | ||
// }); | ||
// } | ||
// | ||
// collection1.rename("", function(err, collection) { | ||
// try { | ||
// collection1.rename("", function(err, collection) {}); | ||
// } catch(err) { | ||
// test.ok(err instanceof Error); | ||
// test.equal("collection names cannot be empty", err.message); | ||
// }); | ||
// test.equal("collection names cannot be empty", err.message); | ||
// } | ||
// | ||
// collection1.rename("te$t", function(err, collection) { | ||
// try { | ||
// collection1.rename("te$t", function(err, collection) {}); | ||
// } catch(err) { | ||
// test.ok(err instanceof Error); | ||
// test.equal("collection names must not contain '$'", err.message); | ||
// }); | ||
// } | ||
// | ||
// collection1.rename(".test", function(err, collection) { | ||
// try { | ||
// collection1.rename(".test", function(err, collection) {}); | ||
// } catch(err) { | ||
// test.ok(err instanceof Error); | ||
// test.equal("collection names must not start or end with '.'", err.message); | ||
// }); | ||
// } | ||
// | ||
// collection1.rename("test.", function(err, collection) { | ||
// try { | ||
// collection1.rename("test.", function(err, collection) {}); | ||
// } catch(err) { | ||
// test.ok(err instanceof Error); | ||
// test.equal("collection names must not start or end with '.'", err.message); | ||
// }); | ||
// } | ||
// | ||
// collection1.rename("tes..t", function(err, collection) { | ||
// try { | ||
// collection1.rename("tes..t", function(err, collection) {}); | ||
// } catch(err) { | ||
// test.equal("collection names cannot be empty", err.message); | ||
// }); | ||
// } | ||
// | ||
// collection1.count(function(err, count) { | ||
// test.equal(0, count); | ||
// | ||
// | ||
// collection1.insert([{'x':1}, {'x':2}], {safe:true}, function(err, docs) { | ||
// collection1.count(function(err, count) { | ||
// test.equal(2, count); | ||
// | ||
// | ||
// collection1.rename('test_rename_collection2', function(err, collection) { | ||
// test.ok(err instanceof Error); | ||
// test.ok(err.message.length > 0); | ||
// | ||
// | ||
// collection1.rename('test_rename_collection3', function(err, collection) { | ||
// test.equal("test_rename_collection3", collection.collectionName); | ||
// | ||
// | ||
// // Check count | ||
@@ -253,3 +315,3 @@ // collection.count(function(err, count) { | ||
// }) | ||
// | ||
// | ||
// collection2.count(function(err, count) { | ||
@@ -256,0 +318,0 @@ // test.equal(0, count); |
@@ -77,25 +77,25 @@ var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure(); | ||
// shouldCorrectlyFindDocumentsByRegExp : function(test) { | ||
// // Serialized regexes contain extra trailing chars. Sometimes these trailing chars contain / which makes | ||
// // the original regex invalid, and leads to segmentation fault. | ||
// client.createCollection('test_regex_serialization', function(err, collection) { | ||
// collection.insert({keywords: ["test", "segmentation", "fault", "regex", "serialization", "native"]}, {safe:true}, function(err, r) { | ||
// | ||
// var count = 20, | ||
// run = function(i) { | ||
// // search by regex | ||
// collection.findOne({keywords: {$all: [/ser/, /test/, /seg/, /fault/, /nat/]}}, function(err, item) { | ||
// test.equal(6, item.keywords.length); | ||
// if (i === 0) { | ||
// test.done() | ||
// } | ||
// }); | ||
// }; | ||
// // loop a few times to catch the / in trailing chars case | ||
// while (count--) { | ||
// run(count); | ||
// } | ||
// }); | ||
// }); | ||
// } | ||
shouldCorrectlyFindDocumentsByRegExp : function(test) { | ||
// Serialized regexes contain extra trailing chars. Sometimes these trailing chars contain / which makes | ||
// the original regex invalid, and leads to segmentation fault. | ||
client.createCollection('test_regex_serialization', function(err, collection) { | ||
collection.insert({keywords: ["test", "segmentation", "fault", "regex", "serialization", "native"]}, {safe:true}, function(err, r) { | ||
var count = 20, | ||
run = function(i) { | ||
// search by regex | ||
collection.findOne({keywords: {$all: [/ser/, /test/, /seg/, /fault/, /nat/]}}, function(err, item) { | ||
test.equal(6, item.keywords.length); | ||
if (i === 0) { | ||
test.done() | ||
} | ||
}); | ||
}; | ||
// loop a few times to catch the / in trailing chars case | ||
while (count--) { | ||
run(count); | ||
} | ||
}); | ||
}); | ||
} | ||
}) | ||
@@ -102,0 +102,0 @@ |
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
1542194
0.16%24651
0.28%171
-0.58%