minor: support dash in host name on parse_uri

This commit is contained in:
Kyle Banker 2010-06-14 22:06:55 -04:00
parent c28b126267
commit 51140f8ea1
2 changed files with 7 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

@ -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]