diff options
Diffstat (limited to 'lib/uri/generic.rb')
-rw-r--r-- | lib/uri/generic.rb | 78 |
1 files changed, 39 insertions, 39 deletions
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 |