RUBY-392 fix to support ruby < 1.9 (1.9 is needed to support named capture groups in regular expressions)

This commit is contained in:
Tyler Brock 2012-01-30 13:53:12 -05:00
parent a193c055ab
commit fb77743f60
2 changed files with 13 additions and 13 deletions

View File

@ -21,15 +21,15 @@ module Mongo
DEFAULT_PORT = 27017 DEFAULT_PORT = 27017
USER_REGEX = /(?<username>[-.\w:]+)/ USER_REGEX = /([-.\w:]+)/
PASS_REGEX = /(?<password>[^@,]+)/ PASS_REGEX = /([^@,]+)/
AUTH_REGEX = /(?<auth>#{USER_REGEX}:#{PASS_REGEX}@)?/ AUTH_REGEX = /(#{USER_REGEX}:#{PASS_REGEX}@)?/
HOST_REGEX = /(?<host>[-.\w]+)/ HOST_REGEX = /([-.\w]+)/
PORT_REGEX = /(?::(?<port>\w+))?/ PORT_REGEX = /(?::(\w+))?/
NODE_REGEX = /(?<nodes>(#{HOST_REGEX}#{PORT_REGEX},?)+)/ NODE_REGEX = /((#{HOST_REGEX}#{PORT_REGEX},?)+)/
PATH_REGEX = /(?:\/(?<path>[-\w]+))?/ PATH_REGEX = /(?:\/([-\w]+))?/
MONGODB_URI_MATCHER = /#{AUTH_REGEX}#{NODE_REGEX}#{PATH_REGEX}/ MONGODB_URI_MATCHER = /#{AUTH_REGEX}#{NODE_REGEX}#{PATH_REGEX}/
MONGODB_URI_SPEC = "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]" MONGODB_URI_SPEC = "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]"
@ -160,10 +160,10 @@ module Mongo
raise MongoArgumentError, "MongoDB URI must match this spec: #{MONGODB_URI_SPEC}" raise MongoArgumentError, "MongoDB URI must match this spec: #{MONGODB_URI_SPEC}"
end end
uname = matches['username'] uname = matches[2]
pwd = matches['password'] pwd = matches[3]
hosturis = matches['nodes'].split(',') hosturis = matches[4].split(',')
db = matches['path'] db = matches[8]
hosturis.each do |hosturi| hosturis.each do |hosturi|
# If port is present, use it, otherwise use default port # If port is present, use it, otherwise use default port
@ -200,7 +200,7 @@ module Mongo
separator = opts.include?('&') ? '&' : ';' separator = opts.include?('&') ? '&' : ';'
opts.split(separator).each do |attr| opts.split(separator).each do |attr|
key, value = attr.split('=') key, value = attr.split('=')
key = key.to_sym.downcase key = key.downcase.to_sym
value = value.strip.downcase value = value.strip.downcase
if !OPT_ATTRS.include?(key) if !OPT_ATTRS.include?(key)
raise MongoArgumentError, "Invalid Mongo URI option #{key}" raise MongoArgumentError, "Invalid Mongo URI option #{key}"

View File

@ -608,7 +608,7 @@ class TestCollection < Test::Unit::TestCase
m = Code.new("function() { emit(this.user_id, 1); }") m = Code.new("function() { emit(this.user_id, 1); }")
r = Code.new("function(k,vals) { return 1; }") r = Code.new("function(k,vals) { return 1; }")
res = @@test.map_reduce(m, r, :out => {:replace => 'foo', :db => 'somedb'}) res = @@test.map_reduce(m, r, :out => {:replace => "foo", :db => 'somedb'})
assert res["result"] assert res["result"]
assert res["counts"] assert res["counts"]
assert res["timeMillis"] assert res["timeMillis"]