summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-12 20:39:11 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-12 20:39:11 +0000
commite2b3183fc2c065f8aa9ae77f5ef7d0c8e29744af (patch)
treec968dc11a0fbf99ad2f6adcb249c7967e469bacb /lib
parent78e06ab19423518300a2ef9478cef69468e9d4a9 (diff)
* re.c (Init_Regexp): Document option constants. Patch by Vincent
Batts. [Ruby 1.9 - Bug #4677] * lib/uri/common.rb (module URI): Documentation for URI. Patch by Vincent Batts. [Ruby 1.9- Bug #4677] * lib/uri/ftp.rb (module URI): ditto * lib/uri/generic.rb (module URI): ditto * lib/uri/http.rb (module URI): ditto * lib/uri/https.rb (module URI): ditto * lib/uri/ldap.rb (module URI): ditto * lib/uri/ldaps.rb (module URI): ditto * lib/uri/mailto.rb (module URI): ditto * process.c (Init_process): Document Process constants. Patch by Vincent Batts. [Ruby 1.9- Bug #4677] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31536 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/uri/common.rb107
-rw-r--r--lib/uri/ftp.rb51
-rw-r--r--lib/uri/generic.rb434
-rw-r--r--lib/uri/http.rb9
-rw-r--r--lib/uri/https.rb1
-rw-r--r--lib/uri/ldap.rb68
-rw-r--r--lib/uri/ldaps.rb1
-rw-r--r--lib/uri/mailto.rb13
8 files changed, 678 insertions, 6 deletions
diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index 3bfe33ac64..db53872fec 100644
--- a/lib/uri/common.rb
+++ b/lib/uri/common.rb
@@ -7,6 +7,9 @@
#
module URI
+ #
+ # Includes URI::REGEXP::PATTERN
+ #
module REGEXP
#
# Patterns used to parse URI's
@@ -51,6 +54,10 @@ module URI
# :startdoc:
end # REGEXP
+ # class that Parses String's into URI's
+ #
+ # It contains a Hash set of patterns and Regexp's that match and validate.
+ #
class Parser
include REGEXP
@@ -95,8 +102,18 @@ module URI
@regexp.each_value {|v| v.freeze}
@regexp.freeze
end
- attr_reader :pattern, :regexp
+ # The Hash of patterns.
+ #
+ # see also URI::Parser.initialize_pattern
+ attr_reader :pattern
+
+ # The Hash of Regexp
+ #
+ # see also URI::Parser.initialize_regexp
+ attr_reader :regexp
+
+ # Returns a split URI against regexp[:ABS_URI]
def split(uri)
case uri
when ''
@@ -169,6 +186,23 @@ module URI
return ret
end
+ #
+ # == Args
+ #
+ # +uri+::
+ # String
+ #
+ # == Description
+ #
+ # parses +uri+ and constructs either matching URI scheme object
+ # (FTP, HTTP, HTTPS, LDAP, LDAPS, or MailTo) or URI::Generic
+ #
+ # == Usage
+ #
+ # p = URI::Parser.new
+ # p.parse("ldap://ldap.example.com/dc=example?user=john")
+ # #=> #<URI::LDAP:0x00000000b9e7e8 URL:ldap://ldap.example.com/dc=example?user=john>
+ #
def parse(uri)
scheme, userinfo, host, port,
registry, path, opaque, query, fragment = self.split(uri)
@@ -184,11 +218,43 @@ module URI
end
end
+
+ #
+ # == Args
+ #
+ # +uris+::
+ # an Array of Strings
+ #
+ # == Description
+ #
+ # Attempts to parse and merge a set of URIs
+ #
def join(*uris)
uris[0] = URI(uris[0], self)
uris.inject :merge
end
+ #
+ # :call-seq:
+ # extract( str )
+ # extract( str, schemes )
+ # extract( str, schemes ) {|item| block }
+ #
+ # == Args
+ #
+ # +str+::
+ # String to search
+ # +schemes+::
+ # Patterns to apply to +str+
+ #
+ # == Description
+ #
+ # Attempts to parse and merge a set of URIs
+ # If no +block+ given , then returns the result,
+ # else it calls +block+ for each element in result.
+ #
+ # see also URI::Parser.make_regexp
+ #
def extract(str, schemes = nil, &block)
if block_given?
str.scan(make_regexp(schemes)) { yield $& }
@@ -200,6 +266,8 @@ module URI
end
end
+ # returns Regexp that is default self.regexp[:ABS_URI_REF],
+ # unless +schemes+ is provided. Then it is a Regexp.union with self.pattern[:X_ABS_URI]
def make_regexp(schemes = nil)
unless schemes
@regexp[:ABS_URI_REF]
@@ -208,6 +276,22 @@ module URI
end
end
+ #
+ # :call-seq:
+ # escape( str )
+ # escape( str, unsafe )
+ #
+ # == Args
+ #
+ # +str+::
+ # String to make safe
+ # +unsafe+::
+ # Regexp to apply. Defaults to self.regexp[:UNSAFE]
+ #
+ # == Description
+ #
+ # constructs a safe String from +str+, removing unsafe characters, replacing them with codes.
+ #
def escape(str, unsafe = @regexp[:UNSAFE])
unless unsafe.kind_of?(Regexp)
# perhaps unsafe is String object
@@ -223,6 +307,22 @@ module URI
end.force_encoding(Encoding::US_ASCII)
end
+ #
+ # :call-seq:
+ # unescape( str )
+ # unescape( str, unsafe )
+ #
+ # == Args
+ #
+ # +str+::
+ # String to remove escapes from
+ # +unsafe+::
+ # Regexp to apply. Defaults to self.regexp[:ESCAPED]
+ #
+ # == Description
+ #
+ # Removes escapes from +str+
+ #
def unescape(str, escaped = @regexp[:ESCAPED])
str.gsub(escaped) { [$&[1, 2].hex].pack('C') }.force_encoding(str.encoding)
end
@@ -234,6 +334,7 @@ module URI
private
+ # Constructs the default Hash of patterns
def initialize_pattern(opts = {})
ret = {}
ret[:ESCAPED] = escaped = (opts.delete(:ESCAPED) || PATTERN::ESCAPED)
@@ -391,6 +492,7 @@ module URI
ret
end
+ # Constructs the default Hash of Regexp's
def initialize_regexp(pattern)
ret = {}
@@ -423,6 +525,7 @@ module URI
end
end # class Parser
+ # URI::Parser.new
DEFAULT_PARSER = Parser.new
DEFAULT_PARSER.pattern.each_pair do |sym, str|
unless REGEXP::PATTERN.const_defined?(sym)
@@ -465,6 +568,7 @@ module URI
module_function :make_components_hash
end
+ # module for escaping unsafe characters with codes.
module Escape
#
# == Synopsis
@@ -535,6 +639,7 @@ module URI
include REGEXP
@@schemes = {}
+ # Returns a Hash of the defined schemes
def self.scheme_list
@@schemes
end
diff --git a/lib/uri/ftp.rb b/lib/uri/ftp.rb
index 4e33dadd33..663ecd5788 100644
--- a/lib/uri/ftp.rb
+++ b/lib/uri/ftp.rb
@@ -19,13 +19,18 @@ module URI
# http://tools.ietf.org/html/draft-hoffman-ftp-uri-04
#
class FTP < Generic
+ # A Default port of 21 for URI::FTP
DEFAULT_PORT = 21
+ #
+ # An Array of the available components for URI::FTP
+ #
COMPONENT = [
:scheme,
:userinfo, :host, :port,
:path, :typecode
].freeze
+
#
# Typecode is "a", "i" or "d".
#
@@ -34,8 +39,19 @@ module URI
# * "d" indicates the contents of a directory should be displayed
#
TYPECODE = ['a', 'i', 'd'].freeze
+
+ # Typecode prefix
+ # ';type='
TYPECODE_PREFIX = ';type='.freeze
+ # alternate initialization
+ # Creates a new URI::FTP object.
+ #
+ # Unlike build(), this method does not escape the path component as required by
+ # RFC1738; instead it is treated as per RFC2396.
+ #
+ # Arguments are user, password, host, port, path, typecode,
+ # and arg_check, in that order.
def self.new2(user, password, host, port, path,
typecode = nil, arg_check = true)
typecode = nil if typecode.size == 0
@@ -133,8 +149,15 @@ module URI
end
end
end
+
+ # typecode accessor
+ #
+ # see URI::FTP::COMPONENT
attr_reader :typecode
+ # validates typecode +v+,
+ # returns a +true+ or +false+ boolean
+ #
def check_typecode(v)
if TYPECODE.include?(v)
return true
@@ -145,11 +168,39 @@ module URI
end
private :check_typecode
+ # private setter for the typecode +v+
+ #
+ # see also URI::FTP.typecode=
+ #
def set_typecode(v)
@typecode = v
end
protected :set_typecode
+ #
+ # == Args
+ #
+ # +v+::
+ # String
+ #
+ # == Description
+ #
+ # public setter for the typecode +v+.
+ # (with validation)
+ #
+ # see also URI::FTP.check_typecode
+ #
+ # == Usage
+ #
+ # require 'uri'
+ #
+ # uri = URI.parse("ftp://john@ftp.example.com/my_file.img")
+ # #=> #<URI::FTP:0x00000000923650 URL:ftp://john@ftp.example.com/my_file.img>
+ # uri.typecode = "i"
+ # # => "i"
+ # uri
+ # #=> #<URI::FTP:0x00000000923650 URL:ftp://john@ftp.example.com/my_file.img;type=i>
+ #
def typecode=(typecode)
check_typecode(typecode)
set_typecode(typecode)
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
index 161d666ccb..a5121001e2 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -18,6 +18,9 @@ module URI
class Generic
include URI
+ #
+ # A Default port of nil for URI::Generic
+ #
DEFAULT_PORT = nil
#
@@ -27,10 +30,16 @@ module URI
self::DEFAULT_PORT
end
+ #
+ # Returns default port
+ #
def default_port
self.class.default_port
end
+ #
+ # An Array of the available components for URI::Generic
+ #
COMPONENT = [
:scheme,
:userinfo, :host, :port, :registry,
@@ -46,10 +55,14 @@ module URI
self::COMPONENT
end
+ #
+ # Default to not use the registry for a URI::Generic
+ #
USE_REGISTRY = false
#
- # DOC: FIXME!
+ # Returns whether a registry of naming
+ # authorities are being used.
#
def self.use_registry
self::USE_REGISTRY
@@ -138,11 +151,11 @@ module URI
# +port+::
# Server port
# +registry+::
- # DOC: FIXME!
+ # Registry of naming authorities.
# +path+::
# Path on server
# +opaque+::
- # DOC: FIXME!
+ # Opaque part
# +query+::
# Query data
# +fragment+::
@@ -206,6 +219,11 @@ module URI
self.set_port(self.default_port) if self.default_port && !@port
end
+ #
+ # returns the scheme component of the URI.
+ #
+ # URI("http://foo/bar/baz").scheme #=> "http"
+ #
attr_reader :scheme
# returns the host component of the URI.
@@ -230,13 +248,52 @@ module URI
#
attr_reader :host
+ # returns the port component of the URI.
+ #
+ # URI("http://foo/bar/baz").port #=> "80"
+ #
+ # URI("http://foo:8080/bar/baz").port #=> "8080"
+ #
attr_reader :port
+
+ # returns the registry component of the URI.
+ #
+ # (see RFC2396 Section 3.2)
+ #
attr_reader :registry
+
+ # returns the path component of the URI.
+ #
+ # URI("http://foo/bar/baz").path #=> "/bar/baz"
+ #
attr_reader :path
+
+ # returns the query component of the URI.
+ #
+ # URI("http://foo/bar/baz?search=FooBar").query #=> "search=FooBar"
+ #
attr_reader :query
+
+ # returns the opaque part of the URI.
+ #
+ # URI("mailto:foo@example.org").opaque #=> "foo@example.org"
+ #
+ # Portion of the path that does make use of the slash '/'.
+ # The path typically refers to the absolute path and the opaque part.
+ # (see RFC2396 Section 3 and 5.2)
+ #
attr_reader :opaque
+
+ # returns the fragment component of the URI.
+ #
+ # URI("http://foo/bar/baz?search=FooBar#ponies").fragment #=> "ponies"
+ #
attr_reader :fragment
+ # returns the parser to be used.
+ #
+ # Unless a URI::Parser is defined, then DEFAULT_PARSER is used.
+ #
def parser
if !defined?(@parser) || !@parser
DEFAULT_PARSER
@@ -257,10 +314,16 @@ module URI
end
private :replace!
+ #
+ # Components of the URI in the order.
+ #
def component
self.class.component
end
+ #
+ # check the scheme +v+ component against the URI::Parser Regexp for :SCHEME
+ #
def check_scheme(v)
if v && parser.regexp[:SCHEME] !~ v
raise InvalidComponentError,
@@ -271,17 +334,53 @@ module URI
end
private :check_scheme
+ # protected setter for the scheme component +v+
+ #
+ # see also URI::Generic.scheme=
+ #
def set_scheme(v)
@scheme = v
end
protected :set_scheme
+ #
+ # == Args
+ #
+ # +v+::
+ # String
+ #
+ # == Description
+ #
+ # public setter for the scheme component +v+.
+ # (with validation)
+ #
+ # see also URI::Generic.check_scheme
+ #
+ # == Usage
+ #
+ # require 'uri'
+ #
+ # uri = URI.parse("http://my.example.com")
+ # uri.scheme = "https"
+ # # => "https"
+ # uri
+ # #=> #<URI::HTTP:0x000000008e89e8 URL:https://my.example.com>
+ #
def scheme=(v)
check_scheme(v)
set_scheme(v)
v
end
+ #
+ # check the +user+ and +password+.
+ #
+ # If +password+ is not provided, then +user+ is
+ # split, using URI::Generic.split_userinfo, to
+ # pull +user+ and +password.
+ #
+ # see also URI::Generic.check_user, URI::Generic.check_password
+ #
def check_userinfo(user, password = nil)
if !password
user, password = split_userinfo(user)
@@ -293,6 +392,13 @@ module URI
end
private :check_userinfo
+ #
+ # check the user +v+ component for RFC2396 compliance
+ # and against the URI::Parser Regexp for :USERINFO
+ #
+ # Can not have a registry or opaque component defined,
+ # with a user component defined.
+ #
def check_user(v)
if @registry || @opaque
raise InvalidURIError,
@@ -310,6 +416,13 @@ module URI
end
private :check_user
+ #
+ # check the password +v+ component for RFC2396 compliance
+ # and against the URI::Parser Regexp for :USERINFO
+ #
+ # Can not have a registry or opaque component defined,
+ # with a user component defined.
+ #
def check_password(v, user = @user)
if @registry || @opaque
raise InvalidURIError,
@@ -343,18 +456,69 @@ module URI
# returns userinfo
end
+ #
+ # == Args
+ #
+ # +v+::
+ # String
+ #
+ # == Description
+ #
+ # public setter for the +user+ component.
+ # (with validation)
+ #
+ # see also URI::Generic.check_user
+ #
+ # == Usage
+ #
+ # require 'uri'
+ #
+ # uri = URI.parse("http://john:S3nsit1ve@my.example.com")
+ # uri.user = "sam"
+ # # => "sam"
+ # uri
+ # #=> #<URI::HTTP:0x00000000881d90 URL:http://sam:V3ry_S3nsit1ve@my.example.com>
+ #
def user=(user)
check_user(user)
set_user(user)
# returns user
end
+ #
+ # == Args
+ #
+ # +v+::
+ # String
+ #
+ # == Description
+ #
+ # public setter for the +password+ component.
+ # (with validation)
+ #
+ # see also URI::Generic.check_password
+ #
+ # == Usage
+ #
+ # require 'uri'
+ #
+ # uri = URI.parse("http://john:S3nsit1ve@my.example.com")
+ # uri.password = "V3ry_S3nsit1ve"
+ # # => "V3ry_S3nsit1ve"
+ # uri
+ # #=> #<URI::HTTP:0x00000000881d90 URL:http://john:V3ry_S3nsit1ve@my.example.com>
+ #
def password=(password)
check_password(password)
set_password(password)
# returns password
end
+ # protect setter for the +user+ component, and +password+ if available.
+ # (with validation)
+ #
+ # see also URI::Generic.userinfo=
+ #
def set_userinfo(user, password = nil)
unless password
user, password = split_userinfo(user)
@@ -366,18 +530,28 @@ module URI
end
protected :set_userinfo
+ # protected setter for the user component +v+
+ #
+ # see also URI::Generic.user=
+ #
def set_user(v)
set_userinfo(v, @password)
v
end
protected :set_user
+ # protected setter for the password component +v+
+ #
+ # see also URI::Generic.password=
+ #
def set_password(v)
@password = v
# returns v
end
protected :set_password
+ # returns the userinfo +ui+ as user, password
+ # if properly formated as 'user:password'
def split_userinfo(ui)
return nil, nil unless ui
user, password = ui.split(/:/, 2)
@@ -386,11 +560,13 @@ module URI
end
private :split_userinfo
+ # escapes 'user:password' +v+ based on RFC 1738 section 3.1
def escape_userpass(v)
v = parser.escape(v, /[@:\/]/o) # RFC 1738 section 3.1 #/
end
private :escape_userpass
+ # returns the userinfo, either as 'user' or 'user:password'
def userinfo
if @user.nil?
nil
@@ -401,14 +577,23 @@ module URI
end
end
+ # returns the user component
def user
@user
end
+ # returns the password component
def password
@password
end
+ #
+ # check the host +v+ component for RFC2396 compliance
+ # and against the URI::Parser Regexp for :HOST
+ #
+ # Can not have a registry or opaque component defined,
+ # with a host component defined.
+ #
def check_host(v)
return v unless v
@@ -424,11 +609,38 @@ module URI
end
private :check_host
+ # protected setter for the host component +v+
+ #
+ # see also URI::Generic.host=
+ #
def set_host(v)
@host = v
end
protected :set_host
+ #
+ # == Args
+ #
+ # +v+::
+ # String
+ #
+ # == Description
+ #
+ # public setter for the host component +v+.
+ # (with validation)
+ #
+ # see also URI::Generic.check_host
+ #
+ # == Usage
+ #
+ # require 'uri'
+ #
+ # uri = URI.parse("http://my.example.com")
+ # uri.host = "foo.com"
+ # # => "foo.com"
+ # uri
+ # #=> #<URI::HTTP:0x000000008e89e8 URL:http://foo.com>
+ #
def host=(v)
check_host(v)
set_host(v)
@@ -467,6 +679,13 @@ module URI
self.host = v
end
+ #
+ # check the port +v+ component for RFC2396 compliance
+ # and against the URI::Parser Regexp for :PORT
+ #
+ # Can not have a registry or opaque component defined,
+ # with a port component defined.
+ #
def check_port(v)
return v unless v
@@ -482,6 +701,10 @@ module URI
end
private :check_port
+ # protected setter for the port component +v+
+ #
+ # see also URI::Generic.port=
+ #
def set_port(v)
unless !v || v.kind_of?(Fixnum)
if v.empty?
@@ -494,12 +717,42 @@ module URI
end
protected :set_port
+ #
+ # == Args
+ #
+ # +v+::
+ # String
+ #
+ # == Description
+ #
+ # public setter for the port component +v+.
+ # (with validation)
+ #
+ # see also URI::Generic.check_port
+ #
+ # == Usage
+ #
+ # require 'uri'
+ #
+ # uri = URI.parse("http://my.example.com")
+ # uri.port = 8080
+ # # => 8080
+ # uri
+ # #=> #<URI::HTTP:0x000000008e89e8 URL:http://my.example.com:8080>
+ #
def port=(v)
check_port(v)
set_port(v)
port
end
+ #
+ # check the registry +v+ component for RFC2396 compliance
+ # and against the URI::Parser Regexp for :REGISTRY
+ #
+ # Can not have a host, port or user component defined,
+ # with a registry component defined.
+ #
def check_registry(v)
return v unless v
@@ -518,17 +771,42 @@ module URI
end
private :check_registry
+ # protected setter for the registry component +v+
+ #
+ # see also URI::Generic.registry=
+ #
def set_registry(v)
@registry = v
end
protected :set_registry
+ #
+ # == Args
+ #
+ # +v+::
+ # String
+ #
+ # == Description
+ #
+ # public setter for the registry component +v+.
+ # (with validation)
+ #
+ # see also URI::Generic.check_registry
+ #
def registry=(v)
check_registry(v)
set_registry(v)
v
end
+ #
+ # check the path +v+ component for RFC2396 compliance
+ # and against the URI::Parser Regexp
+ # for :ABS_PATH and :REL_PATH
+ #
+ # Can not have a opaque component defined,
+ # with a path component defined.
+ #
def check_path(v)
# raise if both hier and opaque are not nil, because:
# absoluteURI = scheme ":" ( hier_part | opaque_part )
@@ -556,17 +834,51 @@ module URI
end
private :check_path
+ # protected setter for the path component +v+
+ #
+ # see also URI::Generic.path=
+ #
def set_path(v)
@path = v
end
protected :set_path
+ #
+ # == Args
+ #
+ # +v+::
+ # String
+ #
+ # == Description
+ #
+ # public setter for the path component +v+.
+ # (with validation)
+ #
+ # see also URI::Generic.check_path
+ #
+ # == Usage
+ #
+ # require 'uri'
+ #
+ # uri = URI.parse("http://my.example.com/pub/files")
+ # uri.path = "/faq/"
+ # # => "/faq/"
+ # uri
+ # #=> #<URI::HTTP:0x000000008e89e8 URL:http://my.example.com/faq/>
+ #
def path=(v)
check_path(v)
set_path(v)
v
end
+ #
+ # check the query +v+ component for RFC2396 compliance
+ # and against the URI::Parser Regexp for :QUERY
+ #
+ # Can not have a opaque component defined,
+ # with a query component defined.
+ #
def check_query(v)
return v unless v
@@ -587,17 +899,51 @@ module URI
end
private :check_query
+ # protected setter for the query component +v+
+ #
+ # see also URI::Generic.query=
+ #
def set_query(v)
@query = v
end
protected :set_query
+ #
+ # == Args
+ #
+ # +v+::
+ # String
+ #
+ # == Description
+ #
+ # public setter for the query component +v+.
+ # (with validation)
+ #
+ # see also URI::Generic.check_query
+ #
+ # == Usage
+ #
+ # require 'uri'
+ #
+ # uri = URI.parse("http://my.example.com/?id=25")
+ # uri.query = "id=1"
+ # # => "id=1"
+ # uri
+ # #=> #<URI::HTTP:0x000000008e89e8 URL:http://my.example.com/?id=1>
+ #
def query=(v)
check_query(v)
set_query(v)
v
end
+ #
+ # check the opaque +v+ component for RFC2396 compliance and
+ # against the URI::Parser Regexp for :OPAQUE
+ #
+ # Can not have a host, port, user or path component defined,
+ # with an opaque component defined.
+ #
def check_opaque(v)
return v unless v
@@ -616,17 +962,37 @@ module URI
end
private :check_opaque
+ # protected setter for the opaque component +v+
+ #
+ # see also URI::Generic.opaque=
+ #
def set_opaque(v)
@opaque = v
end
protected :set_opaque
+ #
+ # == Args
+ #
+ # +v+::
+ # String
+ #
+ # == Description
+ #
+ # public setter for the opaque component +v+.
+ # (with validation)
+ #
+ # see also URI::Generic.check_opaque
+ #
def opaque=(v)
check_opaque(v)
set_opaque(v)
v
end
+ #
+ # check the fragment +v+ component against the URI::Parser Regexp for :FRAGMENT
+ #
def check_fragment(v)
return v unless v
@@ -639,11 +1005,38 @@ module URI
end
private :check_fragment
+ # protected setter for the fragment component +v+
+ #
+ # see also URI::Generic.fragment=
+ #
def set_fragment(v)
@fragment = v
end
protected :set_fragment
+ #
+ # == Args
+ #
+ # +v+::
+ # String
+ #
+ # == Description
+ #
+ # public setter for the fragment component +v+.
+ # (with validation)
+ #
+ # see also URI::Generic.check_fragment
+ #
+ # == Usage
+ #
+ # require 'uri'
+ #
+ # uri = URI.parse("http://my.example.com/?id=25#time=1305212049")
+ # uri.fragment = "time=1305212086"
+ # # => "time=1305212086"
+ # uri
+ # #=> #<URI::HTTP:0x000000007a81f8 URL:http://my.example.com/?id=25#time=1305212086>
+ #
def fragment=(v)
check_fragment(v)
set_fragment(v)
@@ -680,11 +1073,18 @@ module URI
!absolute?
end
+ #
+ # returns an Array of the path split on '/'
+ #
def split_path(path)
path.split(%r{/+}, -1)
end
private :split_path
+ #
+ # Merges a base path +base+, with relative path +rel+,
+ # returns a modified base path.
+ #
def merge_path(base, rel)
# RFC2396, Section 5.2, 5)
@@ -861,6 +1261,7 @@ module URI
end
private :merge0
+ # :stopdoc:
def route_from_path(src, dst)
case dst
when src
@@ -897,7 +1298,9 @@ module URI
return '../' * src_path.size + tmp
end
private :route_from_path
+ # :startdoc:
+ # :stopdoc:
def route_from0(oth)
oth = URI(oth, parser)
if self.relative?
@@ -944,6 +1347,8 @@ module URI
return oth, rel
end
private :route_from0
+ # :startdoc:
+
#
# == Args
#
@@ -1030,6 +1435,7 @@ module URI
end
end
+ # returns the assemble String with path and query components
def path_query
str = @path
if @query
@@ -1115,6 +1521,9 @@ module URI
=begin
=end
+
+
+ # returns an Array of the components defined from the COMPONENT Array
def component_ary
component.collect do |x|
self.send(x)
@@ -1155,6 +1564,25 @@ module URI
@@to_s.bind(self).call.sub!(/>\z/) {" URL:#{self}>"}
end
+ #
+ # == Args
+ #
+ # +v+::
+ # URI or String
+ #
+ # == Description
+ #
+ # attempt to parse other URI +oth+
+ # return [parsed_oth, self]
+ #
+ # == Usage
+ #
+ # require 'uri'
+ #
+ # uri = URI.parse("http://my.example.com")
+ # uri.coerce("http://foo.com")
+ # #=> [#<URI::HTTP:0x00000000bcb028 URL:http://foo.com/>, #<URI::HTTP:0x00000000d92178 URL:http://my.example.com>]
+ #
def coerce(oth)
case oth
when String
diff --git a/lib/uri/http.rb b/lib/uri/http.rb
index 69a7658918..7d63ff52f9 100644
--- a/lib/uri/http.rb
+++ b/lib/uri/http.rb
@@ -19,8 +19,10 @@ module URI
# update. See <URL:http://support.microsoft.com/kb/834489>.
#
class HTTP < Generic
+ # A Default port of 80 for URI::HTTP
DEFAULT_PORT = 80
+ # An Array of the available components for URI::HTTP
COMPONENT = [
:scheme,
:userinfo, :host, :port,
@@ -71,8 +73,11 @@ module URI
#
# Example:
#
- # uri = URI::HTTP.new(['http', nil, "www.example.com", nil, "/path",
- # "query", 'fragment'])
+ # uri = URI::HTTP.new('http', nil, "www.example.com", nil, "/path",
+ # "query", 'fragment')
+ #
+ #
+ # See also URI::Generic.new
#
def initialize(*arg)
super(*arg)
diff --git a/lib/uri/https.rb b/lib/uri/https.rb
index 9761636304..767f3338ab 100644
--- a/lib/uri/https.rb
+++ b/lib/uri/https.rb
@@ -14,6 +14,7 @@ module URI
# than 'http:'. Other than that, HTTPS URIs are identical to HTTP URIs;
# see URI::HTTP.
class HTTPS < HTTP
+ # A Default port of 443 for URI::HTTPS
DEFAULT_PORT = 443
end
@@schemes['HTTPS'] = HTTPS
diff --git a/lib/uri/ldap.rb b/lib/uri/ldap.rb
index 6739a018af..561082a58e 100644
--- a/lib/uri/ldap.rb
+++ b/lib/uri/ldap.rb
@@ -20,8 +20,10 @@ module URI
#
class LDAP < Generic
+ # A Default port of 389 for URI::LDAP
DEFAULT_PORT = 389
+ # An Array of the available components for URI::LDAP
COMPONENT = [
:scheme,
:host, :port,
@@ -32,12 +34,40 @@ module URI
:extensions,
].freeze
+ # Scopes available for the starting point.
+ #
+ # * SCOPE_BASE - the Base DN
+ # * SCOPE_ONE - one level under the Base DN, not including the base DN and not including any entries under this.
+ # * SCOPE_SUB - subtress, all entries at all levels
+ #
SCOPE = [
SCOPE_ONE = 'one',
SCOPE_SUB = 'sub',
SCOPE_BASE = 'base',
].freeze
+ #
+ # == Description
+ #
+ # Create a new URI::LDAP object from components, with syntax checking.
+ #
+ # The components accepted are host, port, dn, attributes,
+ # scope, filter, and extensions.
+ #
+ # The components should be provided either as an Array, or as a Hash
+ # with keys formed by preceding the component names with a colon.
+ #
+ # If an Array is used, the components must be passed in the order
+ # [host, port, dn, attributes, scope, filter, extensions].
+ #
+ # Example:
+ #
+ # newuri = URI::LDAP.build({:host => 'ldap.example.com',
+ # :dn> => '/dc=example'})
+ #
+ # newuri = URI::LDAP.build(["ldap.example.com", nil,
+ # "/dc=example;dc=com", "query", nil, nil, nil])
+ #
def self.build(args)
tmp = Util::make_components_hash(self, args)
@@ -56,6 +86,23 @@ module URI
return super(tmp)
end
+ #
+ # == Description
+ #
+ # Create a new URI::LDAP object from generic URI components as per
+ # RFC 2396. No LDAP-specific syntax checking is performed.
+ #
+ # Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
+ # +opaque+, +query+ and +fragment+, in that order.
+ #
+ # Example:
+ #
+ # uri = URI::LDAP.new("ldap", nil, "ldap.example.com", nil,
+ # "/dc=example;dc=com", "query", nil, nil, nil, nil)
+ #
+ #
+ # See also URI::Generic.new
+ #
def initialize(*arg)
super(*arg)
@@ -67,11 +114,14 @@ module URI
parse_query
end
+ # private method to cleanup +dn+ from using the +path+ component attribute
def parse_dn
@dn = @path[1..-1]
end
private :parse_dn
+ # private method to cleanup +attributes+, +scope+, +filter+ and +extensions+,
+ # from using the +query+ component attribute
def parse_query
@attributes = nil
@scope = nil
@@ -89,6 +139,7 @@ module URI
end
private :parse_query
+ # private method to assemble +query+ from +attributes+, +scope+, +filter+ and +extensions+.
def build_path_query
@path = '/' + @dn
@@ -101,10 +152,12 @@ module URI
end
private :build_path_query
+ # returns dn.
def dn
@dn
end
+ # private setter for dn +val+
def set_dn(val)
@dn = val
build_path_query
@@ -112,15 +165,18 @@ module URI
end
protected :set_dn
+ # setter for dn +val+
def dn=(val)
set_dn(val)
val
end
+ # returns attributes.
def attributes
@attributes
end
+ # private setter for attributes +val+
def set_attributes(val)
@attributes = val
build_path_query
@@ -128,15 +184,18 @@ module URI
end
protected :set_attributes
+ # setter for attributes +val+
def attributes=(val)
set_attributes(val)
val
end
+ # returns scope.
def scope
@scope
end
+ # private setter for scope +val+
def set_scope(val)
@scope = val
build_path_query
@@ -144,15 +203,18 @@ module URI
end
protected :set_scope
+ # setter for scope +val+
def scope=(val)
set_scope(val)
val
end
+ # returns filter.
def filter
@filter
end
+ # private setter for filter +val+
def set_filter(val)
@filter = val
build_path_query
@@ -160,15 +222,18 @@ module URI
end
protected :set_filter
+ # setter for filter +val+
def filter=(val)
set_filter(val)
val
end
+ # returns extensions.
def extensions
@extensions
end
+ # private setter for extensions +val+
def set_extensions(val)
@extensions = val
build_path_query
@@ -176,11 +241,14 @@ module URI
end
protected :set_extensions
+ # setter for extensions +val+
def extensions=(val)
set_extensions(val)
val
end
+ # Checks if URI has a path
+ # For URI::LDAP this will return +false+
def hierarchical?
false
end
diff --git a/lib/uri/ldaps.rb b/lib/uri/ldaps.rb
index 6da333150f..bfea6ce5e7 100644
--- a/lib/uri/ldaps.rb
+++ b/lib/uri/ldaps.rb
@@ -6,6 +6,7 @@ module URI
# than 'ldap:'. Other than that, LDAPS URIs are identical to LDAP URIs;
# see URI::LDAP.
class LDAPS < LDAP
+ # A Default port of 636 for URI::LDAPS
DEFAULT_PORT = 636
end
@@schemes['LDAPS'] = LDAPS
diff --git a/lib/uri/mailto.rb b/lib/uri/mailto.rb
index 3edaac93f3..1e8f2da063 100644
--- a/lib/uri/mailto.rb
+++ b/lib/uri/mailto.rb
@@ -16,8 +16,10 @@ module URI
class MailTo < Generic
include REGEXP
+ # A Default port of nil for URI::MailTo
DEFAULT_PORT = nil
+ # An Array of the available components for URI::MailTo
COMPONENT = [ :scheme, :to, :headers ].freeze
# :stopdoc:
@@ -155,6 +157,9 @@ module URI
# E-mail headers set by the URL, as an Array of Arrays
attr_reader :headers
+ # check the to +v+ component against either
+ # * URI::Parser Regexp for :OPAQUE
+ # * MAILBOX_PATTERN
def check_to(v)
return true unless v
return true if v.size == 0
@@ -168,17 +173,22 @@ module URI
end
private :check_to
+ # private setter for to +v+
def set_to(v)
@to = v
end
protected :set_to
+ # setter for to +v+
def to=(v)
check_to(v)
set_to(v)
v
end
+ # check the headers +v+ component against either
+ # * URI::Parser Regexp for :OPAQUE
+ # * HEADER_PATTERN
def check_headers(v)
return true unless v
return true if v.size == 0
@@ -193,6 +203,7 @@ module URI
end
private :check_headers
+ # private setter for headers +v+
def set_headers(v)
@headers = []
if v
@@ -203,12 +214,14 @@ module URI
end
protected :set_headers
+ # setter for headers +v+
def headers=(v)
check_headers(v)
set_headers(v)
v
end
+ # Constructs String from URI
def to_s
@scheme + ':' +
if @to