From 51140f8ea13cd42abcabc4f0f624d6aa3128042c Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Mon, 14 Jun 2010 22:06:55 -0400 Subject: [PATCH] minor: support dash in host name on parse_uri --- lib/mongo/connection.rb | 2 +- test/unit/connection_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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]