diff --git a/lib/mongo/connection.rb b/lib/mongo/connection.rb index 30ccbec..013ed29 100644 --- a/lib/mongo/connection.rb +++ b/lib/mongo/connection.rb @@ -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 diff --git a/test/unit/connection_test.rb b/test/unit/connection_test.rb index fbd1534..199b73e 100644 --- a/test/unit/connection_test.rb +++ b/test/unit/connection_test.rb @@ -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)