From 63ca1c7648133ed41ff81a3f3b1e6d54f6fc12de Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Tue, 15 Nov 2011 16:31:21 -0500 Subject: [PATCH] RUBY-350 allow ':' in usernames in URI --- lib/mongo/util/uri_parser.rb | 2 +- test/uri_test.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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')