mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* lib/uri/generic.rb (URI::Generic::merge,
URI::Generic::route_from): accepts non-hierarchical URI. [ruby-dev:23631] * test/uri/test_generic.rb (TestGeneric::test_route, TestGeneric::test_merge): added tests for above changes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									4d3805905a
								
							
						
					
					
						commit
						fa1261e093
					
				
					 3 changed files with 54 additions and 19 deletions
				
			
		| 
						 | 
				
			
			@ -726,7 +726,12 @@ module URI
 | 
			
		|||
    #   # =>  #<URI::HTTP:0x2021f3b0 URL:http://my.rubysite.com/main.rbx?page=1>
 | 
			
		||||
    #
 | 
			
		||||
    def merge(oth)
 | 
			
		||||
      base, rel = merge0(oth)
 | 
			
		||||
      begin
 | 
			
		||||
        base, rel = merge0(oth)
 | 
			
		||||
      rescue
 | 
			
		||||
        raise $!.class, $!.message
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      if base == rel
 | 
			
		||||
        return base
 | 
			
		||||
      end
 | 
			
		||||
| 
						 | 
				
			
			@ -734,7 +739,7 @@ module URI
 | 
			
		|||
      authority = rel.userinfo || rel.host || rel.port
 | 
			
		||||
 | 
			
		||||
      # RFC2396, Section 5.2, 2)
 | 
			
		||||
      if rel.path.empty? && !authority && !rel.query
 | 
			
		||||
      if (rel.path.nil? || rel.path.empty?) && !authority && !rel.query
 | 
			
		||||
        base.set_fragment(rel.fragment) if rel.fragment
 | 
			
		||||
        return base
 | 
			
		||||
      end
 | 
			
		||||
| 
						 | 
				
			
			@ -744,10 +749,10 @@ module URI
 | 
			
		|||
 | 
			
		||||
      # RFC2396, Section 5.2, 4)
 | 
			
		||||
      if !authority
 | 
			
		||||
        base.set_path(merge_path(base.path, rel.path))
 | 
			
		||||
        base.set_path(merge_path(base.path, rel.path)) if base.path && rel.path
 | 
			
		||||
      else
 | 
			
		||||
        # RFC2396, Section 5.2, 4)
 | 
			
		||||
        base.set_path(rel.path)
 | 
			
		||||
        base.set_path(rel.path) if rel.path
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      # RFC2396, Section 5.2, 7)
 | 
			
		||||
| 
						 | 
				
			
			@ -785,14 +790,6 @@ module URI
 | 
			
		|||
        return oth, oth
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      if !self.hierarchical?
 | 
			
		||||
        raise BadURIError, 
 | 
			
		||||
          "not hierarchical URI: #{self}"
 | 
			
		||||
      elsif !oth.hierarchical?
 | 
			
		||||
        raise BadURIError, 
 | 
			
		||||
          "not hierarchical URI: #{oth}"
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      if self.absolute?
 | 
			
		||||
        return self.dup, oth
 | 
			
		||||
      else
 | 
			
		||||
| 
						 | 
				
			
			@ -861,12 +858,8 @@ module URI
 | 
			
		|||
          "relative URI: #{oth}"
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      if !self.hierarchical? || !oth.hierarchical?
 | 
			
		||||
        return self, self.dup
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      if self.scheme != oth.scheme
 | 
			
		||||
        return oth, oth.dup
 | 
			
		||||
        return self, self.dup
 | 
			
		||||
      end
 | 
			
		||||
      rel = URI::Generic.new(nil, # it is relative URI
 | 
			
		||||
                             self.userinfo, self.host, self.port, 
 | 
			
		||||
| 
						 | 
				
			
			@ -876,6 +869,9 @@ module URI
 | 
			
		|||
      if rel.userinfo != oth.userinfo ||
 | 
			
		||||
          rel.host.to_s.downcase != oth.host.to_s.downcase ||
 | 
			
		||||
          rel.port != oth.port
 | 
			
		||||
	if self.userinfo.nil? && self.host.nil?
 | 
			
		||||
	  return self, self.dup
 | 
			
		||||
	end
 | 
			
		||||
        rel.set_port(nil) if rel.port == oth.default_port
 | 
			
		||||
        return rel, rel
 | 
			
		||||
      end
 | 
			
		||||
| 
						 | 
				
			
			@ -883,10 +879,14 @@ module URI
 | 
			
		|||
      rel.set_host(nil)
 | 
			
		||||
      rel.set_port(nil)
 | 
			
		||||
 | 
			
		||||
      if rel.path == oth.path
 | 
			
		||||
      if rel.path && rel.path == oth.path
 | 
			
		||||
        rel.set_path('')
 | 
			
		||||
        rel.set_query(nil) if rel.query == oth.query
 | 
			
		||||
        return rel, rel
 | 
			
		||||
      elsif rel.opaque && rel.opaque == oth.opaque
 | 
			
		||||
        rel.set_opaque('')
 | 
			
		||||
        rel.set_query(nil) if rel.query == oth.query
 | 
			
		||||
        return rel, rel
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      # you can modify `rel', but can not `oth'.
 | 
			
		||||
| 
						 | 
				
			
			@ -913,7 +913,11 @@ module URI
 | 
			
		|||
    #
 | 
			
		||||
    def route_from(oth)
 | 
			
		||||
      # you can modify `rel', but can not `oth'.
 | 
			
		||||
      oth, rel = route_from0(oth)
 | 
			
		||||
      begin
 | 
			
		||||
        oth, rel = route_from0(oth)
 | 
			
		||||
      rescue
 | 
			
		||||
        raise $!.class, $!.message
 | 
			
		||||
      end
 | 
			
		||||
      if oth == rel
 | 
			
		||||
        return rel
 | 
			
		||||
      end
 | 
			
		||||
| 
						 | 
				
			
			@ -1045,6 +1049,14 @@ module URI
 | 
			
		|||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def hash
 | 
			
		||||
      self.component_ary.hash
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def eql?(oth)
 | 
			
		||||
      self.component_ary.eql?(oth.component_ary)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
=begin
 | 
			
		||||
 | 
			
		||||
--- URI::Generic#===(oth)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue