Skip to content

Commit

Permalink
made MONGODB_URI_MATCHER regular expression in uri_parser.rb easier t…
Browse files Browse the repository at this point in the history
…o interpret by breaking it into parts
  • Loading branch information
TylerBrock committed Dec 20, 2011
1 parent 63708a5 commit 1d22c75
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/mongo/util/uri_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit 1d22c75

Please sign in to comment.