Skip to content

Commit

Permalink
url_parser that treats an empty tag set as null, not [].
Browse files Browse the repository at this point in the history
  • Loading branch information
jmandel committed Nov 20, 2012
1 parent 49b6157 commit 87fa2b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/mongodb/connection/url_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ exports.parse = function(url, options) {
}
});

// No tags: should be null (not [])
if(dbOptions.read_preference_tags.length === 0) {
dbOptions.read_preference_tags = null;
}

// Validate if there are an invalid write concern combinations
if((dbOptions.w == -1 || dbOptions.w == 0) && (
dbOptions.journal == true
Expand All @@ -219,4 +224,4 @@ exports.parse = function(url, options) {
object.servers = servers;
// Returned parsed object
return object;
}
}
3 changes: 3 additions & 0 deletions test/url_parser_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ exports['Read preferences parsing'] = function(test) {
* @ignore
*/
exports['Read preferences tag parsing'] = function(test) {
var object = parse("mongodb://localhost/db");
test.equal(null, object.db_options.read_preference_tags);

var object = parse("mongodb://localhost/db?readPreferenceTags=dc:ny");
test.deepEqual([{dc:"ny"}], object.db_options.read_preference_tags);

Expand Down

0 comments on commit 87fa2b2

Please sign in to comment.