RUBY-350 allow ':' in usernames in URI

This commit is contained in:
Kyle Banker 2011-11-15 16:31:21 -05:00
parent 9aae390eec
commit 63ca1c7648
2 changed files with 6 additions and 1 deletions

View File

@ -20,7 +20,7 @@ module Mongo
class URIParser
DEFAULT_PORT = 27017
MONGODB_URI_MATCHER = /(([-.\w]+):([^@,]+)@)?((?:(?:[-.\w]+)(?::(?:[\w]+))?,?)+)(\/([-\w]+))?/
MONGODB_URI_MATCHER = /(([-.\w:]+):([^@,]+)@)?((?:(?:[-.\w]+)(?::(?:[\w]+))?,?)+)(\/([-\w]+))?/
MONGODB_URI_SPEC = "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/database]"
SPEC_ATTRS = [:nodes, :auths]
OPT_ATTRS = [:connect, :replicaset, :slaveok, :safe, :w, :wtimeout, :fsync]

View File

@ -36,6 +36,11 @@ class TestThreading < Test::Unit::TestCase
assert_equal "s-_3#%R.t", parser.auths[0]["password"]
end
def test_complex_usernames
parser = Mongo::URIParser.new('mongodb://b:ob:secret.word@a.example.com:27018/test')
assert_equal "b:ob", parser.auths[0]["username"]
end
def test_passwords_contain_no_commas
assert_raise MongoArgumentError do
Mongo::URIParser.new('mongodb://bob:a,b@a.example.com:27018/test')