Allow hypens and underscores in URL credentials.

This commit is contained in:
Lincoln Stoll 2010-06-19 20:15:19 +01:00 committed by Kyle Banker
parent 95dee31368
commit 6e3cc639f6
2 changed files with 8 additions and 1 deletions

View File

@ -32,7 +32,7 @@ module Mongo
STANDARD_HEADER_SIZE = 16
RESPONSE_HEADER_SIZE = 20
MONGODB_URI_MATCHER = /(([.\w\d]+):([\w\d]+)@)?([-.\w\d]+)(:([\w\d]+))?(\/([-\d\w]+))?/
MONGODB_URI_MATCHER = /(([-_.\w\d]+):([-_\w\d]+)@)?([-.\w\d]+)(:([\w\d]+))?(\/([-\d\w]+))?/
MONGODB_URI_SPEC = "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/database]"
attr_reader :logger, :size, :host, :port, :nodes, :auths, :sockets, :checked_out

View File

@ -88,6 +88,13 @@ class ConnectionTest < Test::Unit::TestCase
assert_equal auth_hash, @conn.auths[1]
end
should "parse a uri with a hyphen & underscore in the username or password" do
@conn = Connection.from_uri("mongodb://hyphen-user_name:p-s_s@localhost:27017/db", :connect => false)
assert_equal ['localhost', 27017], @conn.nodes[0]
auth_hash = { 'db_name' => 'db', 'username' => 'hyphen-user_name', "password" => 'p-s_s' }
assert_equal auth_hash, @conn.auths[0]
end
should "attempt to connect" do
TCPSocket.stubs(:new).returns(new_mock_socket)
@conn = Connection.from_uri("mongodb://localhost", :connect => false)