From 1d22c7581133930e7f6b1732f1bdad5285aebf49 Mon Sep 17 00:00:00 2001 From: Tyler Brock Date: Tue, 20 Dec 2011 11:27:40 -0500 Subject: [PATCH 1/4] made MONGODB_URI_MATCHER regular expression in uri_parser.rb easier to interpret by breaking it into parts --- lib/mongo/util/uri_parser.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/mongo/util/uri_parser.rb b/lib/mongo/util/uri_parser.rb index b2af56f..c9d4a2c 100644 --- a/lib/mongo/util/uri_parser.rb +++ b/lib/mongo/util/uri_parser.rb @@ -20,8 +20,20 @@ module Mongo class URIParser DEFAULT_PORT = 27017 - MONGODB_URI_MATCHER = /(([-.\w:]+):([^@,]+)@)?((?:(?:[-.\w]+)(?::(?:[\w]+))?,?)+)(\/([-\w]+))?/ + + USER_REGEX = /([-.\w:]+)/ + PASS_REGEX = /([^@,]+)/ + AUTH_REGEX = /(#{USER_REGEX}:#{PASS_REGEX}@)?/ + + HOST_REGEX = /(?:[-.\w]+)/ + PORT_REGEX = /(?::(?:[\d]+))/ + NODE_REGEX = /((?:#{HOST_REGEX}#{PORT_REGEX}?,?)+)/ + + 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]" + SPEC_ATTRS = [:nodes, :auths] OPT_ATTRS = [:connect, :replicaset, :slaveok, :safe, :w, :wtimeout, :fsync] From 899241eefe37426db38ebc5b42450d6c5914326b Mon Sep 17 00:00:00 2001 From: Tyler Brock Date: Tue, 20 Dec 2011 15:56:00 -0500 Subject: [PATCH 2/4] more readability changes to uri_parser regex --- lib/mongo/util/uri_parser.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/mongo/util/uri_parser.rb b/lib/mongo/util/uri_parser.rb index c9d4a2c..db648c6 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 = /(?::(?:[\d]+))/ - NODE_REGEX = /((?:#{HOST_REGEX}#{PORT_REGEX}?,?)+)/ + HOST_REGEX = /(?[-.\w]+)/ + PORT_REGEX = /(?::(?\d+))?/ + 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]" @@ -130,10 +130,10 @@ module Mongo raise MongoArgumentError, "MongoDB URI must match this spec: #{MONGODB_URI_SPEC}" end - uname = matches[2] - pwd = matches[3] - hosturis = matches[4].split(',') - db = matches[6] + uname = matches['username'] + pwd = matches['password'] + hosturis = matches['nodes'].split(',') + db = matches['path'] hosturis.each do |hosturi| # If port is present, use it, otherwise use default port From d79ca1f9943dda967cb993c166946b00006e90d2 Mon Sep 17 00:00:00 2001 From: Tyler Brock Date: Tue, 20 Dec 2011 16:02:17 -0500 Subject: [PATCH 3/4] small change to regex --- lib/mongo/util/uri_parser.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mongo/util/uri_parser.rb b/lib/mongo/util/uri_parser.rb index db648c6..c5a43bd 100644 --- a/lib/mongo/util/uri_parser.rb +++ b/lib/mongo/util/uri_parser.rb @@ -26,7 +26,7 @@ module Mongo AUTH_REGEX = /(?#{USER_REGEX}:#{PASS_REGEX}@)?/ HOST_REGEX = /(?[-.\w]+)/ - PORT_REGEX = /(?::(?\d+))?/ + PORT_REGEX = /(?::(?\w+))?/ NODE_REGEX = /((?#{HOST_REGEX}#{PORT_REGEX},?)+)/ PATH_REGEX = /(?:\/(?[-\w]+))?/ From b3b50f7273d590c4a98fd1f323073a03a4cf7226 Mon Sep 17 00:00:00 2001 From: Tyler Brock Date: Wed, 4 Jan 2012 13:03:44 -0500 Subject: [PATCH 4/4] changes --- lib/mongo/util/uri_parser.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mongo/util/uri_parser.rb b/lib/mongo/util/uri_parser.rb index c5a43bd..51a1602 100644 --- a/lib/mongo/util/uri_parser.rb +++ b/lib/mongo/util/uri_parser.rb @@ -27,7 +27,7 @@ module Mongo HOST_REGEX = /(?[-.\w]+)/ PORT_REGEX = /(?::(?\w+))?/ - NODE_REGEX = /((?#{HOST_REGEX}#{PORT_REGEX},?)+)/ + NODE_REGEX = /(?(#{HOST_REGEX}#{PORT_REGEX},?)+)/ PATH_REGEX = /(?:\/(?[-\w]+))?/