Skip to content

Commit 51140f8

Browse files
committed
minor: support dash in host name on parse_uri
1 parent c28b126 commit 51140f8

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/mongo/connection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Connection
3232
STANDARD_HEADER_SIZE = 16
3333
RESPONSE_HEADER_SIZE = 20
3434

35-
MONGODB_URI_MATCHER = /(([.\w\d]+):([\w\d]+)@)?([.\w\d]+)(:([\w\d]+))?(\/([-\d\w]+))?/
35+
MONGODB_URI_MATCHER = /(([.\w\d]+):([\w\d]+)@)?([-.\w\d]+)(:([\w\d]+))?(\/([-\d\w]+))?/
3636
MONGODB_URI_SPEC = "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/database]"
3737

3838
attr_reader :logger, :size, :host, :port, :nodes, :auths, :sockets, :checked_out

test/unit/connection_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ def new_mock_db
6666
assert_equal ['localhost', 27017], @conn.nodes[0]
6767
end
6868

69+
should "allow a complex host names" do
70+
host_name = "foo.bar-12345.org"
71+
@conn = Connection.from_uri("mongodb://#{host_name}", :connect => false)
72+
assert_equal [host_name, 27017], @conn.nodes[0]
73+
end
74+
6975
should "parse a uri specifying multiple nodes" do
7076
@conn = Connection.from_uri("mongodb://localhost:27017,mydb.com:27018", :connect => false)
7177
assert_equal ['localhost', 27017], @conn.nodes[0]

0 commit comments

Comments
 (0)