diff --git a/lib/mongo/connection.rb b/lib/mongo/connection.rb index c26bdf7..1dc5edf 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 a387001..fbd1534 100644 --- a/test/unit/connection_test.rb +++ b/test/unit/connection_test.rb @@ -66,6 +66,12 @@ class ConnectionTest < Test::Unit::TestCase assert_equal ['localhost', 27017], @conn.nodes[0] end + should "allow a complex host names" do + host_name = "foo.bar-12345.org" + @conn = Connection.from_uri("mongodb://#{host_name}", :connect => false) + assert_equal [host_name, 27017], @conn.nodes[0] + end + should "parse a uri specifying multiple nodes" do @conn = Connection.from_uri("mongodb://localhost:27017,mydb.com:27018", :connect => false) assert_equal ['localhost', 27017], @conn.nodes[0]