From fb77743f608797f5d1f6b5a63a6880413bb78128 Mon Sep 17 00:00:00 2001 From: Tyler Brock Date: Mon, 30 Jan 2012 13:53:12 -0500 Subject: [PATCH] RUBY-392 fix to support ruby < 1.9 (1.9 is needed to support named capture groups in regular expressions) --- lib/mongo/util/uri_parser.rb | 24 ++++++++++++------------ test/collection_test.rb | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/mongo/util/uri_parser.rb b/lib/mongo/util/uri_parser.rb index 780f3ea..7af63cc 100644 --- a/lib/mongo/util/uri_parser.rb +++ b/lib/mongo/util/uri_parser.rb @@ -21,15 +21,15 @@ module Mongo DEFAULT_PORT = 27017 - USER_REGEX = /(?[-.\w:]+)/ - PASS_REGEX = /(?[^@,]+)/ - AUTH_REGEX = /(?#{USER_REGEX}:#{PASS_REGEX}@)?/ + USER_REGEX = /([-.\w:]+)/ + PASS_REGEX = /([^@,]+)/ + AUTH_REGEX = /(#{USER_REGEX}:#{PASS_REGEX}@)?/ - HOST_REGEX = /(?[-.\w]+)/ - PORT_REGEX = /(?::(?\w+))?/ - NODE_REGEX = /(?(#{HOST_REGEX}#{PORT_REGEX},?)+)/ + HOST_REGEX = /([-.\w]+)/ + PORT_REGEX = /(?::(\w+))?/ + NODE_REGEX = /((#{HOST_REGEX}#{PORT_REGEX},?)+)/ - PATH_REGEX = /(?:\/(?[-\w]+))?/ + PATH_REGEX = /(?:\/([-\w]+))?/ MONGODB_URI_MATCHER = /#{AUTH_REGEX}#{NODE_REGEX}#{PATH_REGEX}/ 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}" end - uname = matches['username'] - pwd = matches['password'] - hosturis = matches['nodes'].split(',') - db = matches['path'] + uname = matches[2] + pwd = matches[3] + hosturis = matches[4].split(',') + db = matches[8] hosturis.each do |hosturi| # If port is present, use it, otherwise use default port @@ -200,7 +200,7 @@ module Mongo separator = opts.include?('&') ? '&' : ';' opts.split(separator).each do |attr| key, value = attr.split('=') - key = key.to_sym.downcase + key = key.downcase.to_sym value = value.strip.downcase if !OPT_ATTRS.include?(key) raise MongoArgumentError, "Invalid Mongo URI option #{key}" diff --git a/test/collection_test.rb b/test/collection_test.rb index 88acfaf..cefd32a 100644 --- a/test/collection_test.rb +++ b/test/collection_test.rb @@ -608,7 +608,7 @@ class TestCollection < Test::Unit::TestCase m = Code.new("function() { emit(this.user_id, 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["counts"] assert res["timeMillis"]