diff --git a/lib/mongo/util/uri_parser.rb b/lib/mongo/util/uri_parser.rb index 9336c93..b2af56f 100644 --- a/lib/mongo/util/uri_parser.rb +++ b/lib/mongo/util/uri_parser.rb @@ -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] diff --git a/test/uri_test.rb b/test/uri_test.rb index 0d17d38..01df2e6 100644 --- a/test/uri_test.rb +++ b/test/uri_test.rb @@ -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')