summaryrefslogtreecommitdiff
path: root/lib/uri
diff options
context:
space:
mode:
Diffstat (limited to 'lib/uri')
-rw-r--r--lib/uri/common.rb54
-rw-r--r--lib/uri/ftp.rb34
-rw-r--r--lib/uri/generic.rb78
-rw-r--r--lib/uri/http.rb26
-rw-r--r--lib/uri/ldap.rb6
-rw-r--r--lib/uri/mailto.rb20
6 files changed, 109 insertions, 109 deletions
diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index 827ed7883d..828b2b8a4a 100644
--- a/lib/uri/common.rb
+++ b/lib/uri/common.rb
@@ -2,7 +2,7 @@
#
# Author:: Akira Yamada <akira@ruby-lang.org>
# Revision:: $Id$
-# License::
+# License::
# You can redistribute it and/or modify it under the same term as Ruby.
#
@@ -34,7 +34,7 @@ module URI
UNRESERVED = "-_.!~*'()#{ALNUM}"
# reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
# "$" | ","
- # reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
+ # reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
# "$" | "," | "[" | "]" (RFC 2732)
RESERVED = ";/?:@&=+$,\\[\\]"
@@ -103,7 +103,7 @@ module URI
# null uri
when @regexp[:ABS_URI]
- scheme, opaque, userinfo, host, port,
+ scheme, opaque, userinfo, host, port,
registry, path, query, fragment = $~[1..-1]
# URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
@@ -119,19 +119,19 @@ module URI
# server = [ [ userinfo "@" ] hostport ]
if !scheme
- raise InvalidURIError,
+ raise InvalidURIError,
"bad URI(absolute but no scheme): #{uri}"
end
if !opaque && (!path && (!host && !registry))
raise InvalidURIError,
- "bad URI(absolute but no path): #{uri}"
+ "bad URI(absolute but no path): #{uri}"
end
when @regexp[:REL_URI]
scheme = nil
opaque = nil
- userinfo, host, port, registry,
+ userinfo, host, port, registry,
rel_segment, abs_path, query, fragment = $~[1..-1]
if rel_segment && abs_path
path = rel_segment + abs_path
@@ -158,7 +158,7 @@ module URI
path = '' if !path && !opaque # (see RFC2396 Section 5.2)
ret = [
- scheme,
+ scheme,
userinfo, host, port, # X
registry, # X
path, # Y
@@ -170,16 +170,16 @@ module URI
end
def parse(uri)
- scheme, userinfo, host, port,
+ scheme, userinfo, host, port,
registry, path, opaque, query, fragment = self.split(uri)
if scheme && URI.scheme_list.include?(scheme.upcase)
- URI.scheme_list[scheme.upcase].new(scheme, userinfo, host, port,
- registry, path, opaque, query,
+ URI.scheme_list[scheme.upcase].new(scheme, userinfo, host, port,
+ registry, path, opaque, query,
fragment, self)
else
- Generic.new(scheme, userinfo, host, port,
- registry, path, opaque, query,
+ Generic.new(scheme, userinfo, host, port,
+ registry, path, opaque, query,
fragment, self)
end
end
@@ -457,7 +457,7 @@ module URI
end
end
else
- raise ArgumentError,
+ raise ArgumentError,
"expected Array of or Hash of components of #{klass.to_s} (#{klass.component[1..-1].join(', ')})"
end
tmp[:scheme] = klass.to_s.sub(/\A.*::/, '').downcase
@@ -538,7 +538,7 @@ module URI
def self.scheme_list
@@schemes
end
-
+
#
# Base class for all URI exceptions.
#
@@ -579,7 +579,7 @@ module URI
# * Opaque
# * Query
# * Fragment
- #
+ #
# == Usage
#
# require 'uri'
@@ -604,7 +604,7 @@ module URI
# == Description
#
# Creates one of the URI's subclasses instance from the string.
- #
+ #
# == Raises
#
# URI::InvalidURIError
@@ -617,11 +617,11 @@ module URI
# uri = URI.parse("http://www.ruby-lang.org/")
# p uri
# # => #<URI::HTTP:0x202281be URL:http://www.ruby-lang.org/>
- # p uri.scheme
- # # => "http"
- # p uri.host
- # # => "www.ruby-lang.org"
- #
+ # p uri.scheme
+ # # => "http"
+ # p uri.host
+ # # => "www.ruby-lang.org"
+ #
def self.parse(uri)
DEFAULT_PARSER.parse(uri)
end
@@ -658,7 +658,7 @@ module URI
#
# == Args
#
- # +str+::
+ # +str+::
# String to extract URIs from.
# +schemes+::
# Limit URI matching to a specific schemes.
@@ -686,25 +686,25 @@ module URI
#
# == Args
#
- # +match_schemes+::
+ # +match_schemes+::
# Array of schemes. If given, resulting regexp matches to URIs
# whose scheme is one of the match_schemes.
- #
+ #
# == Description
# Returns a Regexp object which matches to URI-like strings.
# The Regexp object returned by this method includes arbitrary
# number of capture group (parentheses). Never rely on it's number.
- #
+ #
# == Usage
#
# require 'uri'
#
# # extract first URI from html_string
# html_string.slice(URI.regexp)
- #
+ #
# # remove ftp URIs
# html_string.sub(URI.regexp(['ftp'])
- #
+ #
# # You should not rely on the number of parentheses
# html_string.scan(URI.regexp) do |*matches|
# p $&
diff --git a/lib/uri/ftp.rb b/lib/uri/ftp.rb
index 3afdce01b4..a40b958497 100644
--- a/lib/uri/ftp.rb
+++ b/lib/uri/ftp.rb
@@ -17,12 +17,12 @@ module URI
DEFAULT_PORT = 21
COMPONENT = [
- :scheme,
+ :scheme,
:userinfo, :host, :port,
:path, :typecode
].freeze
#
- # Typecode is "a", "i" or "d".
+ # Typecode is "a", "i" or "d".
#
# * "a" indicates a text file (the FTP command was ASCII)
# * "i" indicates a binary file (FTP command IMAGE)
@@ -31,7 +31,7 @@ module URI
TYPECODE = ['a', 'i', 'd'].freeze
TYPECODE_PREFIX = ';type='.freeze
- def self.new2(user, password, host, port, path,
+ def self.new2(user, password, host, port, path,
typecode = nil, arg_check = true)
typecode = nil if typecode.size == 0
if typecode && !TYPECODE.include?(typecode)
@@ -42,22 +42,22 @@ module URI
# do escape
self.new('ftp',
- [user, password],
- host, port, nil,
- typecode ? path + TYPECODE_PREFIX + typecode : path,
+ [user, password],
+ host, port, nil,
+ typecode ? path + TYPECODE_PREFIX + typecode : path,
nil, nil, nil, arg_check)
end
#
# == Description
#
- # Creates a new URI::FTP object from components, with syntax checking.
+ # Creates a new URI::FTP object from components, with syntax checking.
#
- # The components accepted are +userinfo+, +host+, +port+, +path+ and
+ # The components accepted are +userinfo+, +host+, +port+, +path+ and
# +typecode+.
#
- # The components should be provided either as an Array, or as a Hash
- # with keys formed by preceding the component names with a colon.
+ # 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
# [userinfo, host, port, path, typecode]
@@ -67,11 +67,11 @@ module URI
#
# require 'uri'
#
- # uri = URI::FTP.build(['user:password', 'ftp.example.com', nil,
+ # uri = URI::FTP.build(['user:password', 'ftp.example.com', nil,
# '/path/file.> zip', 'i'])
# puts uri.to_s -> ftp://user:password@ftp.example.com/%2Fpath/file.zip;type=a
#
- # uri2 = URI::FTP.build({:host => 'ftp.example.com',
+ # uri2 = URI::FTP.build({:host => 'ftp.example.com',
# :path => 'ruby/src'})
# puts uri2.to_s -> ftp://ftp.example.com/ruby/src
#
@@ -92,7 +92,7 @@ module URI
if tmp[:typecode]
if tmp[:typecode].size == 1
- tmp[:typecode] = TYPECODE_PREFIX + tmp[:typecode]
+ tmp[:typecode] = TYPECODE_PREFIX + tmp[:typecode]
end
tmp[:path] << tmp[:typecode]
end
@@ -109,7 +109,7 @@ module URI
# Unlike build(), this method does not escape the path component as
# required by RFC1738; instead it is treated as per RFC2396.
#
- # Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
+ # Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
# +opaque+, +query+ and +fragment+, in that order.
#
def initialize(*arg)
@@ -119,7 +119,7 @@ module URI
if tmp
typecode = @path[tmp + TYPECODE_PREFIX.size..-1]
self.set_path(@path[0..tmp - 1])
-
+
if arg[-1]
self.typecode = typecode
else
@@ -164,9 +164,9 @@ module URI
# RFC 1738 specifically states that the path for an FTP URI does not
# include the / which separates the URI path from the URI host. Example:
#
- # ftp://ftp.example.com/pub/ruby
+ # ftp://ftp.example.com/pub/ruby
#
- # The above URI indicates that the client should connect to
+ # The above URI indicates that the client should connect to
# ftp.example.com then cd pub/ruby from the initial login directory.
#
# If you want to cd to an absolute directory, you must include an
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
index 65c6c7379d..adc3805265 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -9,7 +9,7 @@
require 'uri/common'
module URI
-
+
#
# Base class for all URI classes.
# Implements generic URI syntax as per RFC 2396.
@@ -31,10 +31,10 @@ module URI
end
COMPONENT = [
- :scheme,
- :userinfo, :host, :port, :registry,
- :path, :opaque,
- :query,
+ :scheme,
+ :userinfo, :host, :port, :registry,
+ :path, :opaque,
+ :query,
:fragment
].freeze
@@ -62,7 +62,7 @@ module URI
# == Description
#
# At first, tries to create a new URI::Generic instance using
- # URI::Generic::build. But, if exception URI::InvalidComponentError is raised,
+ # URI::Generic::build. But, if exception URI::InvalidComponentError is raised,
# then it URI::Escape.escape all URI components and tries again.
#
#
@@ -71,7 +71,7 @@ module URI
return self.build(args)
rescue InvalidComponentError
if args.kind_of?(Array)
- return self.build(args.collect{|x|
+ return self.build(args.collect{|x|
if x
@parser.escape(x)
else
@@ -117,7 +117,7 @@ module URI
end
end
else
- raise ArgumentError,
+ raise ArgumentError,
"expected Array of or Hash of components of #{self.class} (#{self.class.component.join(', ')})"
end
@@ -155,10 +155,10 @@ module URI
#
# Creates a new URI::Generic instance from ``generic'' components without check.
#
- def initialize(scheme,
- userinfo, host, port, registry,
- path, opaque,
- query,
+ def initialize(scheme,
+ userinfo, host, port, registry,
+ path, opaque,
+ query,
fragment,
parser = DEFAULT_PARSER,
arg_check = false)
@@ -196,10 +196,10 @@ module URI
self.set_fragment(fragment)
end
if @registry && !self.class.use_registry
- raise InvalidURIError,
+ raise InvalidURIError,
"the scheme #{@scheme} does not accept registry part: #{@registry} (or bad hostname?)"
end
-
+
@scheme.freeze if @scheme
self.set_path('') if !@path && !@opaque # (see RFC2396 Section 5.2)
self.set_port(self.default_port) if self.default_port && !@port
@@ -264,7 +264,7 @@ module URI
def check_user(v)
if @registry || @opaque
- raise InvalidURIError,
+ raise InvalidURIError,
"can not set user with registry or opaque"
end
@@ -281,7 +281,7 @@ module URI
def check_password(v, user = @user)
if @registry || @opaque
- raise InvalidURIError,
+ raise InvalidURIError,
"can not set password with registry or opaque"
end
return v unless v
@@ -317,7 +317,7 @@ module URI
set_user(user)
# returns user
end
-
+
def password=(password)
check_password(password)
set_password(password)
@@ -325,7 +325,7 @@ module URI
end
def set_userinfo(user, password = nil)
- unless password
+ unless password
user, password = split_userinfo(user)
end
@user = user
@@ -382,7 +382,7 @@ module URI
return v unless v
if @registry || @opaque
- raise InvalidURIError,
+ raise InvalidURIError,
"can not set host with registry or opaque"
elsif @parser.regexp[:HOST] !~ v
raise InvalidComponentError,
@@ -408,7 +408,7 @@ module URI
return v unless v
if @registry || @opaque
- raise InvalidURIError,
+ raise InvalidURIError,
"can not set port with registry or opaque"
elsif !v.kind_of?(Fixnum) && @parser.regexp[:PORT] !~ v
raise InvalidComponentError,
@@ -444,7 +444,7 @@ module URI
# authority = server | reg_name
# server = [ [ userinfo "@" ] hostport ]
if @host || @port || @user # userinfo = @user + ':' + @password
- raise InvalidURIError,
+ raise InvalidURIError,
"can not set registry with host, port, or userinfo"
elsif v && @parser.regexp[:REGISTRY] !~ v
raise InvalidComponentError,
@@ -471,18 +471,18 @@ module URI
# absoluteURI = scheme ":" ( hier_part | opaque_part )
# hier_part = ( net_path | abs_path ) [ "?" query ]
if v && @opaque
- raise InvalidURIError,
+ raise InvalidURIError,
"path conflicts with opaque"
end
if @scheme
if v && v != '' && @parser.regexp[:ABS_PATH] !~ v
- raise InvalidComponentError,
+ raise InvalidComponentError,
"bad component(expected absolute path component): #{v}"
end
else
if v && v != '' && @parser.regexp[:ABS_PATH] !~ v && @parser.regexp[:REL_PATH] !~ v
- raise InvalidComponentError,
+ raise InvalidComponentError,
"bad component(expected relative path component): #{v}"
end
end
@@ -509,12 +509,12 @@ module URI
# absoluteURI = scheme ":" ( hier_part | opaque_part )
# hier_part = ( net_path | abs_path ) [ "?" query ]
if @opaque
- raise InvalidURIError,
+ raise InvalidURIError,
"query conflicts with opaque"
end
if v && v != '' && @parser.regexp[:QUERY] !~ v
- raise InvalidComponentError,
+ raise InvalidComponentError,
"bad component(expected query component): #{v}"
end
@@ -540,7 +540,7 @@ module URI
# absoluteURI = scheme ":" ( hier_part | opaque_part )
# hier_part = ( net_path | abs_path ) [ "?" query ]
if @host || @port || @user || @path # userinfo = @user + ':' + @password
- raise InvalidURIError,
+ raise InvalidURIError,
"can not set opaque with host, port, userinfo or path"
elsif v && @parser.regexp[:OPAQUE] !~ v
raise InvalidComponentError,
@@ -566,7 +566,7 @@ module URI
return v unless v
if v && v != '' && @parser.regexp[:FRAGMENT] !~ v
- raise InvalidComponentError,
+ raise InvalidComponentError,
"bad component(expected fragment component): #{v}"
end
@@ -784,12 +784,12 @@ module URI
end
if self.relative? && oth.relative?
- raise BadURIError,
+ raise BadURIError,
"both URI are relative"
end
if self.absolute? && oth.absolute?
- #raise BadURIError,
+ #raise BadURIError,
# "both URI are absolute"
# hmm... should return oth for usability?
return oth, oth
@@ -810,7 +810,7 @@ module URI
src_path = split_path(src)
dst_path = split_path(dst)
- # hmm... dst has abnormal absolute path,
+ # hmm... dst has abnormal absolute path,
# like "/./", "/../", "/x/../", ...
if dst_path.include?('..') ||
dst_path.include?('.')
@@ -855,11 +855,11 @@ module URI
end
if self.relative?
- raise BadURIError,
+ raise BadURIError,
"relative URI: #{self}"
end
if oth.relative?
- raise BadURIError,
+ raise BadURIError,
"relative URI: #{oth}"
end
@@ -867,7 +867,7 @@ module URI
return self, self.dup
end
rel = URI::Generic.new(nil, # it is relative URI
- self.userinfo, self.host, self.port,
+ self.userinfo, self.host, self.port,
self.registry, self.path, self.opaque,
self.query, self.fragment, @parser)
@@ -955,7 +955,7 @@ module URI
# uri = URI.parse('http://my.example.com')
# p uri.route_to('http://my.example.com/main.rbx?page=1')
# #=> #<URI::Generic:0x2020c2f6 URL:/main.rbx?page=1>
- #
+ #
def route_to(oth)
case oth
when Generic
@@ -971,7 +971,7 @@ module URI
#
# Returns normalized URI
- #
+ #
def normalize
uri = dup
uri.normalize!
@@ -987,7 +987,7 @@ module URI
end
if host && host != host.downcase
set_host(self.host.downcase)
- end
+ end
end
def path_query
@@ -1001,7 +1001,7 @@ module URI
#
# Constructs String from URI
- #
+ #
def to_s
str = ''
if @scheme
@@ -1103,7 +1103,7 @@ module URI
if component.include?(c)
self.send(c)
else
- raise ArgumentError,
+ raise ArgumentError,
"expected of components of #{self.class} (#{self.class.component.join(', ')})"
end
end
diff --git a/lib/uri/http.rb b/lib/uri/http.rb
index 87eb8893f2..69a7658918 100644
--- a/lib/uri/http.rb
+++ b/lib/uri/http.rb
@@ -14,18 +14,18 @@ module URI
# The syntax of HTTP URIs is defined in RFC1738 section 3.3.
#
# Note that the Ruby URI library allows HTTP URLs containing usernames and
- # passwords. This is not legal as per the RFC, but used to be
- # supported in Internet Explorer 5 and 6, before the MS04-004 security
+ # passwords. This is not legal as per the RFC, but used to be
+ # supported in Internet Explorer 5 and 6, before the MS04-004 security
# update. See <URL:http://support.microsoft.com/kb/834489>.
#
class HTTP < Generic
DEFAULT_PORT = 80
COMPONENT = [
- :scheme,
- :userinfo, :host, :port,
- :path,
- :query,
+ :scheme,
+ :userinfo, :host, :port,
+ :path,
+ :query,
:fragment
].freeze
@@ -37,21 +37,21 @@ module URI
# The components accepted are userinfo, host, port, path, query and
# fragment.
#
- # The components should be provided either as an Array, or as a Hash
- # with keys formed by preceding the component names with a colon.
+ # 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
# [userinfo, host, port, path, query, fragment].
#
# Example:
#
- # newuri = URI::HTTP.build({:host => 'www.example.com',
+ # newuri = URI::HTTP.build({:host => 'www.example.com',
# :path> => '/foo/bar'})
#
- # newuri = URI::HTTP.build([nil, "www.example.com", nil, "/path",
+ # newuri = URI::HTTP.build([nil, "www.example.com", nil, "/path",
# "query", 'fragment'])
#
- # Currently, if passed userinfo components this method generates
+ # Currently, if passed userinfo components this method generates
# invalid HTTP URIs as per RFC 1738.
#
def self.build(args)
@@ -63,10 +63,10 @@ module URI
# == Description
#
# Create a new URI::HTTP object from generic URI components as per
- # RFC 2396. No HTTP-specific syntax checking (as per RFC 1738) is
+ # RFC 2396. No HTTP-specific syntax checking (as per RFC 1738) is
# performed.
#
- # Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
+ # Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
# +opaque+, +query+ and +fragment+, in that order.
#
# Example:
diff --git a/lib/uri/ldap.rb b/lib/uri/ldap.rb
index 163d2cda24..6739a018af 100644
--- a/lib/uri/ldap.rb
+++ b/lib/uri/ldap.rb
@@ -1,10 +1,10 @@
#
# = uri/ldap.rb
#
-# Author::
+# Author::
# Takaaki Tateishi <ttate@jaist.ac.jp>
# Akira Yamada <akira@ruby-lang.org>
-# License::
+# License::
# URI::LDAP is copyrighted free software by Takaaki Tateishi and Akira Yamada.
# You can redistribute it and/or modify it under the same term as Ruby.
# Revision:: $Id$
@@ -21,7 +21,7 @@ module URI
class LDAP < Generic
DEFAULT_PORT = 389
-
+
COMPONENT = [
:scheme,
:host, :port,
diff --git a/lib/uri/mailto.rb b/lib/uri/mailto.rb
index 38f972e1fb..4fab6e23a5 100644
--- a/lib/uri/mailto.rb
+++ b/lib/uri/mailto.rb
@@ -68,20 +68,20 @@ module URI
#
# If a Hash is used, the keys are the component names preceded by colons.
#
- # The headers can be supplied as a pre-encoded string, such as
+ # The headers can be supplied as a pre-encoded string, such as
# "subject=subscribe&cc=address", or as an Array of Arrays like
# [['subject', 'subscribe'], ['cc', 'address']]
#
# Examples:
- #
+ #
# require 'uri'
- #
+ #
# m1 = URI::MailTo.build(['joe@example.com', 'subject=Ruby'])
# puts m1.to_s -> mailto:joe@example.com?subject=Ruby
- #
+ #
# m2 = URI::MailTo.build(['john@example.com', [['Subject', 'Ruby'], ['Cc', 'jack@example.com']]])
# puts m2.to_s -> mailto:john@example.com?Subject=Ruby&Cc=jack@example.com
- #
+ #
# m3 = URI::MailTo.build({:to => 'listman@example.com', :headers => [['subject', 'subscribe']]})
# puts m3.to_s -> mailto:listman@example.com?subject=subscribe
#
@@ -183,7 +183,7 @@ module URI
return true unless v
return true if v.size == 0
- if @parser.regexp[:OPAQUE] !~ v ||
+ if @parser.regexp[:OPAQUE] !~ v ||
/\A(#{HEADER_PATTERN}(?:\&#{HEADER_PATTERN})*)\z/o !~ v
raise InvalidComponentError,
"bad component(expected opaque component): #{v}"
@@ -210,12 +210,12 @@ module URI
end
def to_s
- @scheme + ':' +
- if @to
+ @scheme + ':' +
+ if @to
@to
else
''
- end +
+ end +
if @headers.size > 0
'?' + @headers.collect{|x| x.join('=')}.join('&')
else
@@ -227,7 +227,7 @@ module URI
''
end
end
-
+
# Returns the RFC822 e-mail text equivalent of the URL, as a String.
#
# Example: